<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>SA实战 ·《SpringCloud Alibaba实战》第11章-服务容错加餐：Sentinel核心技术与配置规则（最全使用教程） | 冰河技术</title>
    <meta name="generator" content="VuePress 1.9.7">
    <link rel="icon" href="/favicon.ico">
    <script charset="utf-8" async="async" src="/js/jquery.min.js"></script>
    <script charset="utf-8" async="async" src="/js/global.js"></script>
    <script charset="utf-8" async="async" src="/js/fingerprint2.min.js"></script>
    <script charset="utf-8" async="async" src="https://v1.cnzz.com/z_stat.php?id=1281063564&amp;web_id=1281063564"></script>
    <script charset="utf-8" async="async" src="https://s9.cnzz.com/z_stat.php?id=1281064551&amp;web_id=1281064551"></script>
    <script>
            var _hmt = _hmt || [];
            (function() {
              var hm = document.createElement("script");
              hm.src = "https://hm.baidu.com/hm.js?d091d2fd0231588b1d0f9231e24e3f5e";
              var s = document.getElementsByTagName("script")[0];
              s.parentNode.insertBefore(hm, s);
            })();
            </script>
    <meta name="description" content="包含：编程语言，开发技术，分布式，微服务，高并发，高可用，高可扩展，高可维护，JVM技术，MySQL，分布式数据库，分布式事务，云原生，大数据，云计算，渗透技术，各种面试题，面试技巧...">
    <meta property="article:modified_time" content="2022-05-23T11:30:51.000Z">
    <meta property="og:title" content="SA实战 ·《SpringCloud Alibaba实战》第11章-服务容错加餐：Sentinel核心技术与配置规则（最全使用教程）">
    <meta property="og:type" content="article">
    <meta property="og:url" content="/md/microservices/springcloudalibaba/2022-05-05-SA%E5%AE%9E%E6%88%98-%E7%AC%AC11%E7%AB%A0-%E6%9C%8D%E5%8A%A1%E5%AE%B9%E9%94%99%E5%8A%A0%E9%A4%90-Sentinel%E6%A0%B8%E5%BF%83%E6%8A%80%E6%9C%AF%E4%B8%8E%E9%85%8D%E7%BD%AE%E8%A7%84%E5%88%99.html">
    <meta name="twitter:title" content="SA实战 ·《SpringCloud Alibaba实战》第11章-服务容错加餐：Sentinel核心技术与配置规则（最全使用教程）">
    <meta name="twitter:url" content="/md/microservices/springcloudalibaba/2022-05-05-SA%E5%AE%9E%E6%88%98-%E7%AC%AC11%E7%AB%A0-%E6%9C%8D%E5%8A%A1%E5%AE%B9%E9%94%99%E5%8A%A0%E9%A4%90-Sentinel%E6%A0%B8%E5%BF%83%E6%8A%80%E6%9C%AF%E4%B8%8E%E9%85%8D%E7%BD%AE%E8%A7%84%E5%88%99.html">
    <meta name="twitter:card" content="summary_large_image">
    <meta name="robots" content="all">
    <meta name="author" content="冰河">
    <meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate">
    <meta http-equiv="Pragma" content="no-cache">
    <meta http-equiv="Expires" content="0">
    <meta name="keywords" content="冰河，冰河技术, 编程语言，开发技术，分布式，微服务，高并发，高可用，高可扩展，高可维护，JVM技术，MySQL，分布式数据库，分布式事务，云原生，大数据，云计算，渗透技术，各种面试题，面试技巧">
    <meta name="apple-mobile-web-app-capable" content="yes">
    
    <link rel="preload" href="/assets/css/0.styles.ab888ebb.css" as="style"><link rel="preload" href="/assets/css/styles.css?v=1653305936337" as="style"><link rel="preload" href="/assets/js/cg-styles.js?v=1653305936337" as="script"><link rel="preload" href="/assets/js/cg-app.js?v=1653305936337" as="script"><link rel="preload" href="/assets/js/cg-4.js?v=1653305936337" as="script"><link rel="preload" href="/assets/js/cg-3.js?v=1653305936337" as="script"><link rel="preload" href="/assets/js/cg-299.js?v=1653305936337" as="script"><link rel="preload" href="/assets/js/cg-5.js?v=1653305936337" as="script"><link rel="preload" href="/assets/js/cg-6.js?v=1653305936337" as="script">
    <link rel="stylesheet" href="/assets/css/0.styles.ab888ebb.css"><link rel="stylesheet" href="/assets/css/styles.css?v=1653305936337">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container"><header class="navbar"><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/" class="home-link router-link-active"><!----> <span class="site-name">冰河技术</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/md/other/guide-to-reading.html" class="nav-link">
  导读
</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="核心技术" class="dropdown-title"><span class="title">核心技术</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>
          Java核心技术
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/core/java/basics/2022-04-28-全网最全正则表达式总结.html" class="nav-link">
  Java基础
</a></li><li class="dropdown-subitem"><a href="/md/core/java/advanced/default.html" class="nav-link">
  Java进阶
</a></li><li class="dropdown-subitem"><a href="/md/core/java/senior/default.html" class="nav-link">
  Java高级
</a></li><li class="dropdown-subitem"><a href="/md/core/java/java8/2022-03-31-001-Java8有哪些新特性呢？.html" class="nav-link">
  Java8新特性
</a></li></ul></li><li class="dropdown-item"><h4>
          Spring核心技术
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/core/spring/ioc/2022-04-04-001-聊聊Spring注解驱动开发那些事儿.html" class="nav-link">
  IOC核心技术
</a></li><li class="dropdown-subitem"><a href="/md/core/spring/aop/default.html" class="nav-link">
  AOP核心技术
</a></li></ul></li><li class="dropdown-item"><h4>
          JVM核心技术
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/core/jvm/2022-04-18-001-JVM调优的几种场景.html" class="nav-link">
  JVM调优技术
</a></li></ul></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="性能调优" class="dropdown-title"><span class="title">性能调优</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/md/performance/jvm/default.html" class="nav-link">
  JVM性能调优
</a></li><li class="dropdown-item"><!----> <a href="/md/performance/tomcat/default.html" class="nav-link">
  Tomcat性能调优
</a></li><li class="dropdown-item"><!----> <a href="/md/performance/mysql/default.html" class="nav-link">
  MySQL性能调优
</a></li><li class="dropdown-item"><!----> <a href="/md/performance/system/default.html" class="nav-link">
  操作系统性能调优
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="并发编程" class="dropdown-title"><span class="title">并发编程</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/md/concurrent/bottom/default.html" class="nav-link">
  底层技术
</a></li><li class="dropdown-item"><!----> <a href="/md/concurrent/source/2020-03-30-001-一文搞懂线程与多线程.html" class="nav-link">
  源码分析
</a></li><li class="dropdown-item"><!----> <a href="/md/concurrent/basics/2020-03-30-001-明明中断了线程，却为何不起作用呢？.html" class="nav-link">
  基础案例
</a></li><li class="dropdown-item"><!----> <a href="/md/concurrent/ActualCombat/default.html" class="nav-link">
  实战案例
</a></li><li class="dropdown-item"><!----> <a href="/md/concurrent/interview/default.html" class="nav-link">
  面试
</a></li><li class="dropdown-item"><!----> <a href="/md/concurrent/framework/default.html" class="nav-link">
  系统架构
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="框架源码" class="dropdown-title"><span class="title">框架源码</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/md/frame/spring/default.html" class="nav-link">
  Spring源码
</a></li><li class="dropdown-item"><!----> <a href="/md/frame/springmvc/default.html" class="nav-link">
  SpringMVC源码
</a></li><li class="dropdown-item"><!----> <a href="/md/frame/mybatis/default.html" class="nav-link">
  MyBatis源码
</a></li><li class="dropdown-item"><!----> <a href="/md/frame/dubbo/default.html" class="nav-link">
  Dubbo源码
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="分布式" class="dropdown-title"><span class="title">分布式</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>
          缓存技术
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/distributed/cache/default.html" class="nav-link">
  Redis
</a></li></ul></li><li class="dropdown-item"><h4>
          服务注册发现
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/distributed/zookeeper/default.html" class="nav-link">
  Zookeeper
</a></li></ul></li><li class="dropdown-item"><h4>
          消息中间件
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/distributed/mq/rabbitmq/default.html" class="nav-link">
  RabbitMQ
</a></li><li class="dropdown-subitem"><a href="/md/distributed/mq/rocketmq/default.html" class="nav-link">
  RocketMQ
</a></li><li class="dropdown-subitem"><a href="/md/distributed/mq/kafka/default.html" class="nav-link">
  Kafka
</a></li></ul></li><li class="dropdown-item"><h4>
          网络通信
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/distributed/netty/default.html" class="nav-link">
  Netty
</a></li></ul></li><li class="dropdown-item"><h4>
          远程调用
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/distributed/dubbo/default.html" class="nav-link">
  Dubbo
</a></li></ul></li><li class="dropdown-item"><h4>
          数据库
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/distributed/mongodb/default.html" class="nav-link">
  MongoDB
</a></li></ul></li><li class="dropdown-item"><h4>
          搜索引擎
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/distributed/es/default.html" class="nav-link">
  ElasticSearch
</a></li></ul></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="微服务" class="dropdown-title"><span class="title">微服务</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/md/microservices/springboot/default.html" class="nav-link">
  SpringBoot
</a></li><li class="dropdown-item"><!----> <a href="/md/microservices/springcloudalibaba/2022-04-02-SpringCloudAlibaba专栏开篇.html" class="nav-link">
  SpringCloudAlibaba
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="中间件" class="dropdown-title"><span class="title">中间件</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/md/middleware/bytecode/2022-04-11-001-工作多年的你依然重复做着CRUD-是否接触过这种技术.html" class="nav-link">
  字节码编程
</a></li><li class="dropdown-item"><!----> <a href="/md/middleware/threadpool/default.html" class="nav-link">
  手写线程池
</a></li><li class="dropdown-item"><!----> <a href="/md/middleware/limiter/default.html" class="nav-link">
  分布式限流
</a></li><li class="dropdown-item"><!----> <a href="/md/middleware/independent/default.html" class="nav-link">
  开源项目
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="项目实战" class="dropdown-title"><span class="title">项目实战</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/md/microservices/springcloudalibaba/2022-04-02-SpringCloudAlibaba专栏开篇.html" class="nav-link">
  SpringCloud Alibaba实战
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="渗透技术" class="dropdown-title"><span class="title">渗透技术</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/md/hack/environment/2022-04-17-001-安装Kali系统.html" class="nav-link">
  基础环境篇
</a></li><li class="dropdown-item"><!----> <a href="/md/hack/tools/2022-04-17-001-使用Easy-Creds工具攻击无线网络.html" class="nav-link">
  渗透工具篇
</a></li><li class="dropdown-item"><!----> <a href="/md/hack/horse/2022-05-02-001-各种一句话木马大全.html" class="nav-link">
  木马篇
</a></li><li class="dropdown-item"><!----> <a href="/md/hack/sql/2022-05-02-001-sqli-labs-master下载与安装.html" class="nav-link">
  SQL注入篇
</a></li><li class="dropdown-item"><!----> <a href="/md/hack/shell/2022-05-02-001-各种解析漏洞拿shell.html" class="nav-link">
  漏洞拿Shell篇
</a></li><li class="dropdown-item"><!----> <a href="/md/hack/crack/2022-05-02-001-使用rarcrack暴力破解RAR-ZIP-7Z压缩包.html" class="nav-link">
  暴力破解篇
</a></li><li class="dropdown-item"><!----> <a href="/md/hack/bash/2022-05-02-001-3389脚本开启代码(vbs版).html" class="nav-link">
  渗透脚本篇
</a></li><li class="dropdown-item"><!----> <a href="/md/hack/raising/2022-05-02-001-数据库提权.html" class="nav-link">
  数据与系统提权篇
</a></li><li class="dropdown-item"><!----> <a href="/md/hack/client/2022-05-02-001-浏览器渗透.html" class="nav-link">
  客户端渗透篇
</a></li><li class="dropdown-item"><!----> <a href="/md/hack/sociology/2022-05-02-001-Metasploit之社会工程学工具包.html" class="nav-link">
  社会工程学
</a></li><li class="dropdown-item"><!----> <a href="/md/hack/question/2022-05-02-001-HTTP错误4031禁止访问-执行访问被拒绝.html" class="nav-link">
  问题记录篇
</a></li></ul></div></div><div class="nav-item"><a href="/md/interview/2022-04-18-001-面试必问-聊聊JVM性能调优.html" class="nav-link">
  面试必问系列
</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="📚PDF" class="dropdown-title"><span class="title">📚PDF</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>
          出版图书
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/knowledge/book/2022-03-29-深入理解分布式事务.html" class="nav-link">
  《深入理解分布式事务：原理与实战》
</a></li><li class="dropdown-subitem"><a href="/md/knowledge/book/2022-03-29-MySQL技术大全.html" class="nav-link">
  《MySQL技术大全：开发、优化与运维实战》
</a></li><li class="dropdown-subitem"><a href="/md/knowledge/book/2022-03-29-海量数据处理与大数据技术实战.html" class="nav-link">
  《海量数据处理与大数据技术实战》
</a></li></ul></li><li class="dropdown-item"><h4>
          电子书籍
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/knowledge/pdf/2022-03-30-《冰河的渗透实战笔记》电子书，442页，37万字，正式发布.html" class="nav-link">
  冰河的渗透实战笔记
</a></li></ul></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="关于" class="dropdown-title"><span class="title">关于</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/md/about/me/about-me.html" class="nav-link">
  关于自己
</a></li><li class="dropdown-item"><!----> <a href="/md/about/study/default.html" class="nav-link">
  关于学习
</a></li><li class="dropdown-item"><!----> <a href="/md/about/job/default.html" class="nav-link">
  关于职场
</a></li></ul></div></div><div class="nav-item"><a href="https://space.bilibili.com/517638832" target="_blank" rel="noopener noreferrer" class="nav-link external">
  B站
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></div><div class="nav-item"><a href="https://github.com/binghe001/BingheGuide" target="_blank" rel="noopener noreferrer" class="nav-link external">
  Github
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></div> <!----></nav></div></header> <div class="sidebar-mask"></div> <aside class="sidebar"><nav class="nav-links"><div class="nav-item"><a href="/md/other/guide-to-reading.html" class="nav-link">
  导读
</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="核心技术" class="dropdown-title"><span class="title">核心技术</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>
          Java核心技术
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/core/java/basics/2022-04-28-全网最全正则表达式总结.html" class="nav-link">
  Java基础
</a></li><li class="dropdown-subitem"><a href="/md/core/java/advanced/default.html" class="nav-link">
  Java进阶
</a></li><li class="dropdown-subitem"><a href="/md/core/java/senior/default.html" class="nav-link">
  Java高级
</a></li><li class="dropdown-subitem"><a href="/md/core/java/java8/2022-03-31-001-Java8有哪些新特性呢？.html" class="nav-link">
  Java8新特性
</a></li></ul></li><li class="dropdown-item"><h4>
          Spring核心技术
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/core/spring/ioc/2022-04-04-001-聊聊Spring注解驱动开发那些事儿.html" class="nav-link">
  IOC核心技术
</a></li><li class="dropdown-subitem"><a href="/md/core/spring/aop/default.html" class="nav-link">
  AOP核心技术
</a></li></ul></li><li class="dropdown-item"><h4>
          JVM核心技术
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/core/jvm/2022-04-18-001-JVM调优的几种场景.html" class="nav-link">
  JVM调优技术
</a></li></ul></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="性能调优" class="dropdown-title"><span class="title">性能调优</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/md/performance/jvm/default.html" class="nav-link">
  JVM性能调优
</a></li><li class="dropdown-item"><!----> <a href="/md/performance/tomcat/default.html" class="nav-link">
  Tomcat性能调优
</a></li><li class="dropdown-item"><!----> <a href="/md/performance/mysql/default.html" class="nav-link">
  MySQL性能调优
</a></li><li class="dropdown-item"><!----> <a href="/md/performance/system/default.html" class="nav-link">
  操作系统性能调优
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="并发编程" class="dropdown-title"><span class="title">并发编程</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/md/concurrent/bottom/default.html" class="nav-link">
  底层技术
</a></li><li class="dropdown-item"><!----> <a href="/md/concurrent/source/2020-03-30-001-一文搞懂线程与多线程.html" class="nav-link">
  源码分析
</a></li><li class="dropdown-item"><!----> <a href="/md/concurrent/basics/2020-03-30-001-明明中断了线程，却为何不起作用呢？.html" class="nav-link">
  基础案例
</a></li><li class="dropdown-item"><!----> <a href="/md/concurrent/ActualCombat/default.html" class="nav-link">
  实战案例
</a></li><li class="dropdown-item"><!----> <a href="/md/concurrent/interview/default.html" class="nav-link">
  面试
</a></li><li class="dropdown-item"><!----> <a href="/md/concurrent/framework/default.html" class="nav-link">
  系统架构
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="框架源码" class="dropdown-title"><span class="title">框架源码</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/md/frame/spring/default.html" class="nav-link">
  Spring源码
</a></li><li class="dropdown-item"><!----> <a href="/md/frame/springmvc/default.html" class="nav-link">
  SpringMVC源码
</a></li><li class="dropdown-item"><!----> <a href="/md/frame/mybatis/default.html" class="nav-link">
  MyBatis源码
</a></li><li class="dropdown-item"><!----> <a href="/md/frame/dubbo/default.html" class="nav-link">
  Dubbo源码
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="分布式" class="dropdown-title"><span class="title">分布式</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>
          缓存技术
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/distributed/cache/default.html" class="nav-link">
  Redis
</a></li></ul></li><li class="dropdown-item"><h4>
          服务注册发现
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/distributed/zookeeper/default.html" class="nav-link">
  Zookeeper
</a></li></ul></li><li class="dropdown-item"><h4>
          消息中间件
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/distributed/mq/rabbitmq/default.html" class="nav-link">
  RabbitMQ
</a></li><li class="dropdown-subitem"><a href="/md/distributed/mq/rocketmq/default.html" class="nav-link">
  RocketMQ
</a></li><li class="dropdown-subitem"><a href="/md/distributed/mq/kafka/default.html" class="nav-link">
  Kafka
</a></li></ul></li><li class="dropdown-item"><h4>
          网络通信
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/distributed/netty/default.html" class="nav-link">
  Netty
</a></li></ul></li><li class="dropdown-item"><h4>
          远程调用
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/distributed/dubbo/default.html" class="nav-link">
  Dubbo
</a></li></ul></li><li class="dropdown-item"><h4>
          数据库
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/distributed/mongodb/default.html" class="nav-link">
  MongoDB
</a></li></ul></li><li class="dropdown-item"><h4>
          搜索引擎
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/distributed/es/default.html" class="nav-link">
  ElasticSearch
</a></li></ul></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="微服务" class="dropdown-title"><span class="title">微服务</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/md/microservices/springboot/default.html" class="nav-link">
  SpringBoot
</a></li><li class="dropdown-item"><!----> <a href="/md/microservices/springcloudalibaba/2022-04-02-SpringCloudAlibaba专栏开篇.html" class="nav-link">
  SpringCloudAlibaba
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="中间件" class="dropdown-title"><span class="title">中间件</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/md/middleware/bytecode/2022-04-11-001-工作多年的你依然重复做着CRUD-是否接触过这种技术.html" class="nav-link">
  字节码编程
</a></li><li class="dropdown-item"><!----> <a href="/md/middleware/threadpool/default.html" class="nav-link">
  手写线程池
</a></li><li class="dropdown-item"><!----> <a href="/md/middleware/limiter/default.html" class="nav-link">
  分布式限流
</a></li><li class="dropdown-item"><!----> <a href="/md/middleware/independent/default.html" class="nav-link">
  开源项目
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="项目实战" class="dropdown-title"><span class="title">项目实战</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/md/microservices/springcloudalibaba/2022-04-02-SpringCloudAlibaba专栏开篇.html" class="nav-link">
  SpringCloud Alibaba实战
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="渗透技术" class="dropdown-title"><span class="title">渗透技术</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/md/hack/environment/2022-04-17-001-安装Kali系统.html" class="nav-link">
  基础环境篇
</a></li><li class="dropdown-item"><!----> <a href="/md/hack/tools/2022-04-17-001-使用Easy-Creds工具攻击无线网络.html" class="nav-link">
  渗透工具篇
</a></li><li class="dropdown-item"><!----> <a href="/md/hack/horse/2022-05-02-001-各种一句话木马大全.html" class="nav-link">
  木马篇
</a></li><li class="dropdown-item"><!----> <a href="/md/hack/sql/2022-05-02-001-sqli-labs-master下载与安装.html" class="nav-link">
  SQL注入篇
</a></li><li class="dropdown-item"><!----> <a href="/md/hack/shell/2022-05-02-001-各种解析漏洞拿shell.html" class="nav-link">
  漏洞拿Shell篇
</a></li><li class="dropdown-item"><!----> <a href="/md/hack/crack/2022-05-02-001-使用rarcrack暴力破解RAR-ZIP-7Z压缩包.html" class="nav-link">
  暴力破解篇
</a></li><li class="dropdown-item"><!----> <a href="/md/hack/bash/2022-05-02-001-3389脚本开启代码(vbs版).html" class="nav-link">
  渗透脚本篇
</a></li><li class="dropdown-item"><!----> <a href="/md/hack/raising/2022-05-02-001-数据库提权.html" class="nav-link">
  数据与系统提权篇
</a></li><li class="dropdown-item"><!----> <a href="/md/hack/client/2022-05-02-001-浏览器渗透.html" class="nav-link">
  客户端渗透篇
</a></li><li class="dropdown-item"><!----> <a href="/md/hack/sociology/2022-05-02-001-Metasploit之社会工程学工具包.html" class="nav-link">
  社会工程学
</a></li><li class="dropdown-item"><!----> <a href="/md/hack/question/2022-05-02-001-HTTP错误4031禁止访问-执行访问被拒绝.html" class="nav-link">
  问题记录篇
</a></li></ul></div></div><div class="nav-item"><a href="/md/interview/2022-04-18-001-面试必问-聊聊JVM性能调优.html" class="nav-link">
  面试必问系列
</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="📚PDF" class="dropdown-title"><span class="title">📚PDF</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>
          出版图书
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/knowledge/book/2022-03-29-深入理解分布式事务.html" class="nav-link">
  《深入理解分布式事务：原理与实战》
</a></li><li class="dropdown-subitem"><a href="/md/knowledge/book/2022-03-29-MySQL技术大全.html" class="nav-link">
  《MySQL技术大全：开发、优化与运维实战》
</a></li><li class="dropdown-subitem"><a href="/md/knowledge/book/2022-03-29-海量数据处理与大数据技术实战.html" class="nav-link">
  《海量数据处理与大数据技术实战》
</a></li></ul></li><li class="dropdown-item"><h4>
          电子书籍
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/knowledge/pdf/2022-03-30-《冰河的渗透实战笔记》电子书，442页，37万字，正式发布.html" class="nav-link">
  冰河的渗透实战笔记
</a></li></ul></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="关于" class="dropdown-title"><span class="title">关于</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/md/about/me/about-me.html" class="nav-link">
  关于自己
</a></li><li class="dropdown-item"><!----> <a href="/md/about/study/default.html" class="nav-link">
  关于学习
</a></li><li class="dropdown-item"><!----> <a href="/md/about/job/default.html" class="nav-link">
  关于职场
</a></li></ul></div></div><div class="nav-item"><a href="https://space.bilibili.com/517638832" target="_blank" rel="noopener noreferrer" class="nav-link external">
  B站
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></div><div class="nav-item"><a href="https://github.com/binghe001/BingheGuide" target="_blank" rel="noopener noreferrer" class="nav-link external">
  Github
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></div> <!----></nav>  <ul class="sidebar-links"><li><section class="sidebar-group depth-0"><p class="sidebar-heading"><span>SpringBoot</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/md/microservices/springboot/default.html" class="sidebar-link">关于我</a></li></ul></section></li><li><section class="sidebar-group depth-0"><p class="sidebar-heading open"><span>SpringCloudAlibaba</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/md/microservices/springcloudalibaba/2022-04-02-SpringCloudAlibaba专栏开篇.html" class="sidebar-link">SA实战 ·《SpringCloud Alibaba实战》专栏开篇啦</a></li><li><a href="/md/microservices/springcloudalibaba/2022-04-04-SA实战·第一篇-专栏设计.html" class="sidebar-link">SA实战 · 《SpringCloud Alibaba实战》专栏设计</a></li><li><a href="/md/microservices/springcloudalibaba/2022-04-09-SA实战-微服务介绍.html" class="sidebar-link">SA实战 ·《SpringCloud Alibaba实战》微服务介绍</a></li><li><a href="/md/microservices/springcloudalibaba/2022-04-13-SA实战·项目说明-流程设计-技术选型-模块划分.html" class="sidebar-link">SA实战 ·《SpringCloud Alibaba实战》项目说明、流程设计、技术选型与模块划分</a></li><li><a href="/md/microservices/springcloudalibaba/2022-04-18-SA实战-开撸-完成通用模块的开发.html" class="sidebar-link">SA实战 ·《SpringCloud Alibaba实战》开撸：完成通用模块的开发</a></li><li><a href="/md/microservices/springcloudalibaba/2022-04-21-SA实战-完成三大微服务的搭建与交互开发.html" class="sidebar-link">SA实战 ·《SpringCloud Alibaba实战》快速搭建三大微服务并完成交互开发与测试</a></li><li><a href="/md/microservices/springcloudalibaba/2022-04-25-SA实战-服务治理-实现服务的注册与发现.html" class="sidebar-link">SA实战 ·《SpringCloud Alibaba实战》服务治理：实现服务的自动注册与发现</a></li><li><a href="/md/microservices/springcloudalibaba/2022-04-27-SA实战-第8章-服务治理-实现服务调用的负载均衡.html" class="sidebar-link">SA实战 ·《SpringCloud Alibaba实战》第8章-服务治理：实现服务调用的负载均衡</a></li><li><a href="/md/microservices/springcloudalibaba/2022-04-28-SA实战-第9章-服务容错-服务雪崩与容错方案.html" class="sidebar-link">SA实战 ·《SpringCloud Alibaba实战》第9章-服务容错：服务雪崩与容错方案</a></li><li><a href="/md/microservices/springcloudalibaba/2022-05-03-SA实战-第10章-服务容错-Fegin整合Sentinel.html" class="sidebar-link">SA实战 ·《SpringCloud Alibaba实战》第10章-服务容错：项目整合Sentinel实现限流与容错</a></li><li><a href="/md/microservices/springcloudalibaba/2022-05-05-SA实战-第11章-服务容错加餐-Sentinel核心技术与配置规则.html" class="active sidebar-link">SA实战 ·《SpringCloud Alibaba实战》第11章-服务容错加餐：Sentinel核心技术与配置规则（最全使用教程）</a></li><li><a href="/md/microservices/springcloudalibaba/2022-05-08-SA实战-第12章-服务网关-网关概述与核心架构.html" class="sidebar-link">SA实战 ·《SpringCloud Alibaba实战》第12章-服务网关：网关概述与核心架构</a></li><li><a href="/md/microservices/springcloudalibaba/2022-05-08-SA实战-第13章-服务网关-项目整合SpringCloudGateway.html" class="sidebar-link">SA实战 ·《SpringCloud Alibaba实战》第13章-服务网关：项目整合SpringCloud Gateway网关</a></li><li><a href="/md/microservices/springcloudalibaba/2022-05-10-SA实战-第14章-服务网关-SpringCloudGateway核心技术.html" class="sidebar-link">SA实战 ·《SpringCloud Alibaba实战》第14章-服务网关加餐：SpringCloud Gateway核心技术</a></li><li><a href="/md/microservices/springcloudalibaba/2022-05-11-SA实战-第15章-链路追踪-核心原理与解决方案.html" class="sidebar-link">SA实战 ·《SpringCloud Alibaba实战》第15章-链路追踪：核心原理与解决方案</a></li><li><a href="/md/microservices/springcloudalibaba/2022-05-12-SA实战-第16章-链路追踪-项目整合Sleuth实现链路追踪.html" class="sidebar-link">SA实战 ·《SpringCloud Alibaba实战》第16章-链路追踪：项目整合Sleuth实现链路追踪</a></li><li><a href="/md/microservices/springcloudalibaba/2022-05-13-SA实战-第17章-链路追踪-Sleuth整合ZipKin.html" class="sidebar-link">SA实战 ·《SpringCloud Alibaba实战》第17章-链路追踪：Sleuth整合ZipKin</a></li><li><a href="/md/microservices/springcloudalibaba/2022-05-17-SA实战-第18章-消息服务-MQ使用场景与选型对比.html" class="sidebar-link">SA实战 ·《SpringCloud Alibaba实战》第18章-消息服务：MQ使用场景与选型对比</a></li><li><a href="/md/microservices/springcloudalibaba/2022-05-18-SA实战-第19章-消息服务-项目整合RocketMQ.html" class="sidebar-link">SA实战 ·《SpringCloud Alibaba实战》第19章-消息服务：项目整合RocketMQ</a></li><li><a href="/md/microservices/springcloudalibaba/2022-05-20-SA实战-第20章-消息服务-RocketMQ核心技术.html" class="sidebar-link">SA实战 ·《SpringCloud Alibaba实战》第20章-消息服务：RocketMQ核心技术</a></li><li><a href="/md/microservices/springcloudalibaba/2022-05-21-SA实战-第21章-服务配置-服务配置介绍与Nacos核心概念.html" class="sidebar-link">SA实战 ·《SpringCloud Alibaba实战》第21章-服务配置：服务配置介绍与Nacos核心概念</a></li></ul></section></li></ul> </aside> <div><main class="page"> <div class="theme-default-content content__default"><h1 id="sa实战-·《springcloud-alibaba实战》第11章-服务容错加餐-sentinel核心技术与配置规则-最全使用教程"><a href="#sa实战-·《springcloud-alibaba实战》第11章-服务容错加餐-sentinel核心技术与配置规则-最全使用教程" class="header-anchor">#</a> SA实战 ·《SpringCloud Alibaba实战》第11章-服务容错加餐：Sentinel核心技术与配置规则（最全使用教程）</h1> <p><strong>大家好，我是冰河~~</strong></p> <blockquote><p>一不小心《<a href="https://mp.weixin.qq.com/mp/appmsgalbum?__biz=Mzg4MjU0OTM1OA==&amp;action=getalbum&amp;album_id=2337104419664084992&amp;scene=173&amp;from_msgid=2247500408&amp;from_itemidx=1&amp;count=3&amp;nolastread=1#wechat_redirect" target="_blank" rel="noopener noreferrer">SpringCloud Alibaba实战<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a>》专栏都更新到第11章了，再不上车就跟不上了，小伙伴们快跟上啊！</p> <p>注意：本项目完整源码加入 <strong><a href="https://public.zsxq.com/groups/48848484411888.html" target="_blank" rel="noopener noreferrer">冰河技术<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></strong> 知识星球即可获取，文末有优惠券。</p></blockquote> <p>在《<a href="https://mp.weixin.qq.com/mp/appmsgalbum?__biz=Mzg4MjU0OTM1OA==&amp;action=getalbum&amp;album_id=2337104419664084992&amp;scene=173&amp;from_msgid=2247500408&amp;from_itemidx=1&amp;count=3&amp;nolastread=1#wechat_redirect" target="_blank" rel="noopener noreferrer">SpringCloud Alibaba实战<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a>》专栏前面的文章中，我们实现了用户微服务、商品微服务和订单微服务之间的远程调用，并且实现了服务调用的负载均衡。也基于阿里开源的Sentinel实现了服务的限流与容错。今天，就和大家一起来聊聊Sentinel的核心技术与配置规则，这应该是全网最全的Sentinel使用教程了吧。</p> <h2 id="本章总览"><a href="#本章总览" class="header-anchor">#</a> 本章总览</h2> <p>文章有点长呀，小伙伴们耐心看完，并跟着实操每一个案例，相信你一定会对Sentinel有一个全新的认识。</p> <p><img alt="sa-2022-05-05-054" data-src="https://binghe001.github.io/assets/images/microservices/springcloudalibaba/sa-2022-05-05-054.png" loading="lazy" class="lazy"></p> <h2 id="sentinel核心功能"><a href="#sentinel核心功能" class="header-anchor">#</a> Sentinel核心功能</h2> <p>随着微服务的流行，服务和服务之间的稳定性变得越来越重要。Sentinel 以流量为切入点，从流量控制、熔断降级、系统负载保护等多个维度保护服务的稳定性。所以，Sentinel的核心功能包括：<strong>流量控制、熔断降级、系统负载保护</strong>。</p> <h3 id="流量控制"><a href="#流量控制" class="header-anchor">#</a> 流量控制</h3> <p>在高并发、大流量场景下，进入系统的流量如果不加控制的话，系统就很有可能会被流量压垮。所以，在流量正式进入系统之前，需要对流量进行控制，以便使流量均匀、可控的方式进入系统。</p> <p>Sentinel作为一个非常出色的容错组件，能够将不可控的流量经过处理转化成均匀、可控的流量。</p> <h3 id="熔断降级"><a href="#熔断降级" class="header-anchor">#</a> 熔断降级</h3> <p>如果检测到系统中的某个调用链路中某个节点出现故障，比如请求超时、服务宕机或者异常比超出一定阈值时，就会对出现故障的节点的调用频率进行限制，甚至不调用出现故障的节点，让请求能够快速失败并返回，以最大程度避免影响到其他节点的服务而导致系统的级联故障。</p> <p>Sentinel主要通过 <strong>限制并发线程数和响应时间</strong> 对资源的访问进行降级。</p> <p><strong>1.限制并发线程数进行降级</strong></p> <p>Sentinel可以通过限制服务节点的并发线程数量，来减少对其他服务节点的影响。例如，当某个服务节点出现故障，例如响应时间变长，或者直接宕机。此时，对服务的直接影响就是会造成请求线程数的不断堆积。如果这些堆积的线程数达到一定的数量后，对当前服务节点的后续请求就会被拒绝，等到堆积的线程完成任务后再开始继续接收新的请求。</p> <p><strong>2.通过响应时间进行降级</strong></p> <p>Sentinel除了可以通过限制并发线程数进行降级外，也能够通过响应时间进行降级。如果依赖的服务出现响应时间过长的情况，则所有对该服务的请求都会被拒绝，直到过了指定的时间窗口之后才能再次访问该服务。</p> <h3 id="系统负载保护"><a href="#系统负载保护" class="header-anchor">#</a> 系统负载保护</h3> <p>Sentinel提供了系统维度的自适应保护能力。当系统的压力和负载比较高的时候，如果还持续让大量的请求进入系统，此时就有可能将系统压垮，进而导致系统宕机。Sentinel会在集群环境下，将本应服务器A承载的流量转发到其他服务器上，比如转发到服务器B上。如果此时服务器B也处于高负载的状态，则Sentinel会提供相应的保护机制，让系统的入口流量和系统的整体负载达到平衡，让系统整体可用，并且能够最大限度的处理请求。</p> <h2 id="sentinel核心规则"><a href="#sentinel核心规则" class="header-anchor">#</a> Sentinel核心规则</h2> <p>Sentinel的核心规则包括流控规则、熔断规则、热点规则、授权规则和系统规则，每种规则的配置方式不同。接下来，就详细介绍下Sentinel中的每种规则的作用与效果。</p> <p><img alt="sa-2022-05-05-039" data-src="https://binghe001.github.io/assets/images/microservices/springcloudalibaba/sa-2022-05-05-039.png" loading="lazy" class="lazy"></p> <h2 id="流控规则"><a href="#流控规则" class="header-anchor">#</a> 流控规则</h2> <p>Sentinel能够对流量进行控制，主要是监控应用的QPS流量或者并发线程数等指标，如果达到指定的阈值时，就会被流量进行控制，以避免服务被瞬时的高并发流量击垮，保证服务的高可靠性。</p> <h3 id="簇点链路规则"><a href="#簇点链路规则" class="header-anchor">#</a> 簇点链路规则</h3> <p>（1）点击簇点链路菜单，可以看到之前访问过的接口，如下所示。</p> <p><img alt="sa-2022-05-05-001" data-src="https://binghe001.github.io/assets/images/microservices/springcloudalibaba/sa-2022-05-05-001.png" loading="lazy" class="lazy"></p> <p>（2）点击右侧的流控按钮，会弹出新增流控规则的提示框，如下所示。</p> <p><img alt="sa-2022-05-05-002" data-src="https://binghe001.github.io/assets/images/microservices/springcloudalibaba/sa-2022-05-05-002.png" loading="lazy" class="lazy"></p> <p>这里，每个配置项的说明如下所示。</p> <ul><li>资源名：资源的唯一名称，默认就是请求的接口路径，可以自行修改，但是要保证唯一。</li> <li>针对来源：具体针对某个微服务进行限流，默认值为default，表示不区分来源，全部限流。</li> <li>阈值类型：QPS表示通过QPS进行限流，并发线程数表示通过并发线程数限流。</li> <li>单机阈值：与阈值类型组合使用。如果阈值类型选择的是QPS，表示当调用接口的QPS达到阈值时，进行限流操作。如果阈值类型选择的是并发线程数，则表示当调用接口的并发线程数达到阈值时，进行限流操作。</li> <li>是否集群：选中则表示集群环境，不选中则表示非集群环境。</li></ul> <h3 id="配置简单限流"><a href="#配置简单限流" class="header-anchor">#</a> 配置简单限流</h3> <p>这里，针对<code>http://localhost:8080/order/test_sentinel</code>接口进行简单的配置，在新增流控规则里阈值类型选择QPS，单机阈值输入3，表示每秒钟的请求量如果超过3，则会触发Sentinel的限流操作。</p> <p><img alt="sa-2022-05-05-003" data-src="https://binghe001.github.io/assets/images/microservices/springcloudalibaba/sa-2022-05-05-003.png" loading="lazy" class="lazy"></p> <p>点击新增按钮后，会为<code>http://localhost:8080/order/test_sentinel</code>接口新增一条限流规则，如下所示。</p> <p><img alt="sa-2022-05-05-004" data-src="https://binghe001.github.io/assets/images/microservices/springcloudalibaba/sa-2022-05-05-004.png" loading="lazy" class="lazy"></p> <p>接下来，在浏览器上快速刷新<code>http://localhost:8080/order/test_sentinel</code>接口，当每秒钟的刷新频率超过3次时，会出现如下所示的提示信息。</p> <p><img alt="sa-2022-05-05-005" data-src="https://binghe001.github.io/assets/images/microservices/springcloudalibaba/sa-2022-05-05-005.png" loading="lazy" class="lazy"></p> <h3 id="配置流控模式"><a href="#配置流控模式" class="header-anchor">#</a> 配置流控模式</h3> <p>点击<code>http://localhost:8080/order/test_sentinel</code>接口流控规则后面的编辑按钮，打开编辑流控规则弹出框（如果是首次配置的话，就是新增流控规则弹出框），点击高级选项配置。</p> <p><img alt="sa-2022-05-05-006" data-src="https://binghe001.github.io/assets/images/microservices/springcloudalibaba/sa-2022-05-05-006.png" loading="lazy" class="lazy"></p> <p>会显示出如下所示的界面。</p> <p><img alt="sa-2022-05-05-007" data-src="https://binghe001.github.io/assets/images/microservices/springcloudalibaba/sa-2022-05-05-007.png" loading="lazy" class="lazy"></p> <p>可以看到，Sentinel主要提供了三种流控模式，分别为直接、关联和链路。</p> <ul><li>直接：默认的流控模式，当接口达到限流条件时，直接开启限流功能。</li> <li>关联：当关联的资源达到限流条件时，开启限流功能。</li> <li>链路：当从某个接口请求过来的资源达到限流条件时，开启限流功能。</li></ul> <h4 id="演示直接流控模式"><a href="#演示直接流控模式" class="header-anchor">#</a> 演示直接流控模式</h4> <p>Sentinel默认就是使用的直接流控模式，我们之前在订单微服务中集成的就是Sentinel的直接流控模式，在本文的流控规则-配置简单限流中，也是使用的直接流控模式，这里不再赘述。</p> <h4 id="演示关联流控模式"><a href="#演示关联流控模式" class="header-anchor">#</a> 演示关联流控模式</h4> <p>（1）在订单微服务的<code>io.binghe.shop.order.controller.OrderController</code> 类中新增 <code>/test_sentinel2</code>接口，如下所示。</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token annotation punctuation">@GetMapping</span><span class="token punctuation">(</span>value <span class="token operator">=</span> <span class="token string">&quot;/test_sentinel2&quot;</span><span class="token punctuation">)</span>
<span class="token keyword">public</span> <span class="token class-name">String</span> <span class="token function">testSentinel2</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
    log<span class="token punctuation">.</span><span class="token function">info</span><span class="token punctuation">(</span><span class="token string">&quot;测试Sentinel2&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token keyword">return</span> <span class="token string">&quot;sentinel2&quot;</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><p>（2）在浏览器上访问下<code>http://localhost:8080/order/test_sentinel2</code>接口，以便使Sentinel检测到<code>http://localhost:8080/order/test_sentinel2</code>接口。</p> <p><img alt="sa-2022-05-05-008" data-src="https://binghe001.github.io/assets/images/microservices/springcloudalibaba/sa-2022-05-05-008.png" loading="lazy" class="lazy"></p> <p><strong>注意：如果想使用Sentinel对某个接口进行限流和降级等操作，一定要先访问下接口，使Sentinel检测出相应的接口，这里一定要注意，在后续的文章中，不再单独说明。</strong></p> <p>（3）回到为<code>http://localhost:8080/order/test_sentinel</code>接口配置流控规则的页面，如下所示。</p> <p><img alt="sa-2022-05-05-009" data-src="https://binghe001.github.io/assets/images/microservices/springcloudalibaba/sa-2022-05-05-009.png" loading="lazy" class="lazy"></p> <p>（4）在流控模式中选择关联，在关联资源中输入<code>/test_sentinel2</code>，如下所示。</p> <p><img alt="sa-2022-05-05-010" data-src="https://binghe001.github.io/assets/images/microservices/springcloudalibaba/sa-2022-05-05-010.png" loading="lazy" class="lazy"></p> <p>点击保存按钮保存配置。</p> <p>（5）打开JMeter，对<code>http://localhost:8080/order/test_sentinel2</code>接口进行测试，使其每秒钟的访问次数大于3，JMeter的具体配置如下所示。</p> <p><img alt="sa-2022-05-05-011" data-src="https://binghe001.github.io/assets/images/microservices/springcloudalibaba/sa-2022-05-05-011.png" loading="lazy" class="lazy"></p> <p>在线程组中配置每秒访问4次。</p> <p><img alt="sa-2022-05-05-012" data-src="https://binghe001.github.io/assets/images/microservices/springcloudalibaba/sa-2022-05-05-012.png" loading="lazy" class="lazy"></p> <p>配置完毕后，使用JMeter开始访问<code>http://localhost:8080/order/test_sentinel2</code>接口。</p> <p>（6）在浏览器上刷新<code>http://localhost:8080/order/test_sentinel</code>接口，发现已经触发了Sentinel的限流功能。</p> <p><img alt="sa-2022-05-05-013" data-src="https://binghe001.github.io/assets/images/microservices/springcloudalibaba/sa-2022-05-05-013.png" loading="lazy" class="lazy"></p> <p>至此，关联流控模式演示完毕。</p> <h4 id="演示链路流控模式"><a href="#演示链路流控模式" class="header-anchor">#</a> 演示链路流控模式</h4> <p>（1）在订单微服务的<code>io.binghe.shop.order.service</code>包中新增SentinelService接口，用于测试流控模式，源码如下所示。</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token comment">/**
 * @author binghe
 * @version 1.0.0
 * @description 测试Sentinel
 */</span>
<span class="token keyword">public</span> <span class="token keyword">interface</span> <span class="token class-name">SentinelService</span> <span class="token punctuation">{</span>

    <span class="token comment">/**
     * 测试方法
     */</span>
    <span class="token keyword">void</span> <span class="token function">sendMessage</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br></div></div><p>（2）在订单微服务的<code>io.binghe.shop.order.service</code>.impl包中新增SentinelServiceImpl类，实现SentinelService接口，源码如下所示。</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token comment">/**
 * @author binghe
 * @version 1.0.0
 * @description 测试类
 */</span>
<span class="token annotation punctuation">@Service</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">SentinelServiceImpl</span> <span class="token keyword">implements</span> <span class="token class-name">SentinelService</span> <span class="token punctuation">{</span>
    <span class="token annotation punctuation">@Override</span>
    <span class="token annotation punctuation">@SentinelResource</span><span class="token punctuation">(</span><span class="token string">&quot;sendMessage&quot;</span><span class="token punctuation">)</span>
    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">sendMessage</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">&quot;测试Sentinel的链路流控模式&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br></div></div><p>这里，我们在sendMessage()方法上使用了@SentinelResource注解， @SentinelResource注解会在后续文章中介绍，这里不再赘述。</p> <p>（3）在订单微服务的<code>io.binghe.shop.order.controller</code>包下新建SentinelController类，用于测试接口，源码如下所示。</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token comment">/**
 * @author binghe
 * @version 1.0.0
 * @description 测试Sentinel
 */</span>
<span class="token annotation punctuation">@Slf4j</span>
<span class="token annotation punctuation">@RestController</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">SentinelController</span> <span class="token punctuation">{</span>

    <span class="token annotation punctuation">@Autowired</span>
    <span class="token keyword">private</span> <span class="token class-name">SentinelService</span> sentinelService<span class="token punctuation">;</span>

    <span class="token annotation punctuation">@GetMapping</span><span class="token punctuation">(</span>value <span class="token operator">=</span> <span class="token string">&quot;/request_sentinel1&quot;</span><span class="token punctuation">)</span>
    <span class="token keyword">public</span> <span class="token class-name">String</span> <span class="token function">requestSentinel1</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
        log<span class="token punctuation">.</span><span class="token function">info</span><span class="token punctuation">(</span><span class="token string">&quot;测试Sentinel1&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        sentinelService<span class="token punctuation">.</span><span class="token function">sendMessage</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">return</span> <span class="token string">&quot;sentinel1&quot;</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    <span class="token annotation punctuation">@GetMapping</span><span class="token punctuation">(</span>value <span class="token operator">=</span> <span class="token string">&quot;/request_sentinel2&quot;</span><span class="token punctuation">)</span>
    <span class="token keyword">public</span> <span class="token class-name">String</span> <span class="token function">requestSentinel2</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
        log<span class="token punctuation">.</span><span class="token function">info</span><span class="token punctuation">(</span><span class="token string">&quot;测试Sentinel2&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        sentinelService<span class="token punctuation">.</span><span class="token function">sendMessage</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">return</span> <span class="token string">&quot;sentinel2&quot;</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br></div></div><p>（4）升级SpringCloud Alibaba的依赖版本到2.2.7.RELEASE，升级SpringCloud版本到Hoxton.SR12，并且加入SpringBoot的管理依赖。主要的修改的是shop-springcloud-alibaba父工程的pom.xml配置，修改后的配置文件如下所示。</p> <div class="language-xml line-numbers-mode"><pre class="language-xml"><code><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>properties</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>java.version</span><span class="token punctuation">&gt;</span></span>1.8<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>java.version</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>project.build.sourceEncoding</span><span class="token punctuation">&gt;</span></span>UTF-8<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>project.build.sourceEncoding</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>spring-cloud.version</span><span class="token punctuation">&gt;</span></span>Hoxton.SR12<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>spring-cloud.version</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>spring-cloud-alibaba.version</span><span class="token punctuation">&gt;</span></span>2.2.7.RELEASE<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>spring-cloud-alibaba.version</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>spring.boot.version</span><span class="token punctuation">&gt;</span></span>2.3.12.RELEASE<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>spring.boot.version</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>logback.version</span><span class="token punctuation">&gt;</span></span>1.1.7<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>logback.version</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>slf4j.version</span><span class="token punctuation">&gt;</span></span>1.7.21<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>slf4j.version</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>common.logging</span><span class="token punctuation">&gt;</span></span>1.2<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>common.logging</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>fastjson.version</span><span class="token punctuation">&gt;</span></span>1.2.51<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>fastjson.version</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>mybatis.version</span><span class="token punctuation">&gt;</span></span>3.4.6<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>mybatis.version</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>mybatis.plus.version</span><span class="token punctuation">&gt;</span></span>3.4.1<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>mybatis.plus.version</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>mysql.jdbc.version</span><span class="token punctuation">&gt;</span></span>8.0.19<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>mysql.jdbc.version</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>druid.version</span><span class="token punctuation">&gt;</span></span>1.1.10<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>druid.version</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>properties</span><span class="token punctuation">&gt;</span></span>

<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dependencyManagement</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dependencies</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dependency</span><span class="token punctuation">&gt;</span></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>groupId</span><span class="token punctuation">&gt;</span></span>org.springframework.boot<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>groupId</span><span class="token punctuation">&gt;</span></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>artifactId</span><span class="token punctuation">&gt;</span></span>spring-boot-starter-parent<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>artifactId</span><span class="token punctuation">&gt;</span></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>version</span><span class="token punctuation">&gt;</span></span>${spring.boot.version}<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>version</span><span class="token punctuation">&gt;</span></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>type</span><span class="token punctuation">&gt;</span></span>pom<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>type</span><span class="token punctuation">&gt;</span></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>scope</span><span class="token punctuation">&gt;</span></span>import<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>scope</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dependency</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dependency</span><span class="token punctuation">&gt;</span></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>groupId</span><span class="token punctuation">&gt;</span></span>org.springframework.cloud<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>groupId</span><span class="token punctuation">&gt;</span></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>artifactId</span><span class="token punctuation">&gt;</span></span>spring-cloud-dependencies<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>artifactId</span><span class="token punctuation">&gt;</span></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>version</span><span class="token punctuation">&gt;</span></span>${spring-cloud.version}<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>version</span><span class="token punctuation">&gt;</span></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>type</span><span class="token punctuation">&gt;</span></span>pom<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>type</span><span class="token punctuation">&gt;</span></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>scope</span><span class="token punctuation">&gt;</span></span>import<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>scope</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dependency</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dependency</span><span class="token punctuation">&gt;</span></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>groupId</span><span class="token punctuation">&gt;</span></span>com.alibaba.cloud<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>groupId</span><span class="token punctuation">&gt;</span></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>artifactId</span><span class="token punctuation">&gt;</span></span>spring-cloud-alibaba-dependencies<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>artifactId</span><span class="token punctuation">&gt;</span></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>version</span><span class="token punctuation">&gt;</span></span>${spring-cloud-alibaba.version}<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>version</span><span class="token punctuation">&gt;</span></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>type</span><span class="token punctuation">&gt;</span></span>pom<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>type</span><span class="token punctuation">&gt;</span></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>scope</span><span class="token punctuation">&gt;</span></span>import<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>scope</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dependency</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dependencies</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dependencyManagement</span><span class="token punctuation">&gt;</span></span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br><span class="line-number">32</span><br><span class="line-number">33</span><br><span class="line-number">34</span><br><span class="line-number">35</span><br><span class="line-number">36</span><br><span class="line-number">37</span><br><span class="line-number">38</span><br><span class="line-number">39</span><br><span class="line-number">40</span><br><span class="line-number">41</span><br></div></div><p>（5）升级Nacos，将Nacos注册中心由1.4.3版本升级为2.1.0版本，并进入Nacos的bin目录，输入如下命令启动Nacos。</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code>startup<span class="token punctuation">.</span>cmd <span class="token operator">-</span>m standalone
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>（6）在订单微服务的application.yml文件中新增链路配置，如下所示。</p> <div class="language-yaml line-numbers-mode"><pre class="language-yaml"><code><span class="token key atrule">spring</span><span class="token punctuation">:</span>
  <span class="token key atrule">cloud</span><span class="token punctuation">:</span>
    <span class="token key atrule">sentinel</span><span class="token punctuation">:</span>
      <span class="token key atrule">web-context-unify</span><span class="token punctuation">:</span> <span class="token boolean important">false</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div><p>（7）在浏览器中分别访问<code>http://localhost:8080/order/request_sentinel1</code>和<code>http://localhost:8080/order/request_sentinel2</code>，查看Sentinel中的簇点链路，如下所示。</p> <p><img alt="sa-2022-05-05-014" data-src="https://binghe001.github.io/assets/images/microservices/springcloudalibaba/sa-2022-05-05-014.png" loading="lazy" class="lazy"></p> <p>（8）点击sendMessage后面的流控按钮，如下所示。</p> <p><img alt="sa-2022-05-05-015" data-src="https://binghe001.github.io/assets/images/microservices/springcloudalibaba/sa-2022-05-05-015.png" loading="lazy" class="lazy"></p> <p>（9）在弹出的新增流控规则编辑框中阈值类型选择QPS，单机阈值输入3，在打开的高级选项中的流控模式选择链路，入口资源输入/request_sentinel1，如下所示。</p> <p><img alt="sa-2022-05-05-016" data-src="https://binghe001.github.io/assets/images/microservices/springcloudalibaba/sa-2022-05-05-016.png" loading="lazy" class="lazy"></p> <p>点击新增按钮保存配置，此时，如果是通过<code>http://localhost:8080/order/request_sentinel1</code>接口调用<code>io.binghe.shop.order.service.SentinelService#sendMessage()</code>方法时，如果调用的频率每秒钟超过3次，就会触发Sentinel的限流操作，而通过<code>http://localhost:8080/order/request_sentinel2</code>接口调用<code>io.binghe.shop.order.service.SentinelService#sendMessage()</code>方法时，则不受限制。</p> <p>（10）在浏览器中不断访问<code>http://localhost:8080/order/request_sentinel1</code>，使得每秒的访问次数超过3，则会触发Sentinel的限流操作，如下所示。</p> <p><img alt="sa-2022-05-05-017" data-src="https://binghe001.github.io/assets/images/microservices/springcloudalibaba/sa-2022-05-05-017.png" loading="lazy" class="lazy"></p> <p>访问<code>http://localhost:8080/order/request_sentinel2</code>接口则不会被限流。</p> <p>至此，链路流控模式演示完毕。</p> <h4 id="附加说明"><a href="#附加说明" class="header-anchor">#</a> 附加说明</h4> <p>在流控规则的高级选项中还有三个流控效果，如下所示。</p> <p><img alt="sa-2022-05-05-018" data-src="https://binghe001.github.io/assets/images/microservices/springcloudalibaba/sa-2022-05-05-018.png" loading="lazy" class="lazy"></p> <p>接下来，就对这三个选项进行简单的说明。</p> <ul><li>快速失败：会直接失败，抛出异常，期间不会做任何其他的处理操作。</li></ul> <p><img alt="sa-2022-05-05-019" data-src="https://binghe001.github.io/assets/images/microservices/springcloudalibaba/sa-2022-05-05-019.png" loading="lazy" class="lazy"></p> <ul><li>Warm Up：从开始阈值到最大QPS阈值会有一个缓冲，可以设置一个预热时长，这个选项比较适合突发瞬时高并发流量的场景，能够将突发的高并发流量转换为均匀、缓慢增长的场景。</li></ul> <p><img alt="sa-2022-05-05-020" data-src="https://binghe001.github.io/assets/images/microservices/springcloudalibaba/sa-2022-05-05-020.png" loading="lazy" class="lazy"></p> <ul><li>排队等待：能够使请求均匀的通过，单机的阈值为每秒通过的请求数量，其余的请求会排队等待。另外，还会设置一个超时时间，当请求超过超时时间未处理时，会被丢弃。</li></ul> <p><img alt="sa-2022-05-05-021" data-src="https://binghe001.github.io/assets/images/microservices/springcloudalibaba/sa-2022-05-05-021.png" loading="lazy" class="lazy"></p> <h2 id="熔断规则"><a href="#熔断规则" class="header-anchor">#</a> 熔断规则</h2> <p>降级规则一般情况下，指的是满足某些条件时，对服务进行降级操作。</p> <h3 id="熔断规则概述"><a href="#熔断规则概述" class="header-anchor">#</a> 熔断规则概述</h3> <p>Sentinel主要提供了三个熔断策略，分别为：慢调用比例、异常比例和异常数。</p> <p><img alt="sa-2022-05-05-033" data-src="https://binghe001.github.io/assets/images/microservices/springcloudalibaba/sa-2022-05-05-033.png" loading="lazy" class="lazy"></p> <h3 id="演示基于慢调用比例熔断"><a href="#演示基于慢调用比例熔断" class="header-anchor">#</a> 演示基于慢调用比例熔断</h3> <p>（1）首先在浏览器中访问<code>http://localhost:8080/order/request_sentinel2</code>，在Sentinel的簇点链路里找到/request_sentinel2</p> <p><img alt="sa-2022-05-05-030" data-src="https://binghe001.github.io/assets/images/microservices/springcloudalibaba/sa-2022-05-05-030.png" loading="lazy" class="lazy"></p> <p>（2）点击熔断按钮，进入熔断规则配置框，按照如下方式进行配置。</p> <p><img alt="sa-2022-05-05-031" data-src="https://binghe001.github.io/assets/images/microservices/springcloudalibaba/sa-2022-05-05-031.png" loading="lazy" class="lazy"></p> <p>上述配置表示最大响应时长为1ms，比例阈值达到0.1时，会触发熔断操作，并且熔断的时长为2，最小请求数未5，统计的时长为1000毫秒。</p> <p>（3）点击新增按钮后，不断在浏览器中刷新<code>http://localhost:8080/order/request_sentinel2</code>，会发现触发了Sentinel的熔断操作，如下所示。</p> <p><img alt="sa-2022-05-05-032" data-src="https://binghe001.github.io/assets/images/microservices/springcloudalibaba/sa-2022-05-05-032.png" loading="lazy" class="lazy"></p> <h3 id="演示基于异常比例熔断"><a href="#演示基于异常比例熔断" class="header-anchor">#</a> 演示基于异常比例熔断</h3> <p>（1）在订单微服务的<code>io.binghe.shop.order.controller.SentinelController</code>类中定义一个成员变量count，用来记录访问计数，同时，新增一个requestSentinel4()方法用来测试基于异常比例的熔断，如下所示。</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token keyword">private</span> <span class="token keyword">int</span> count <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span>
<span class="token annotation punctuation">@GetMapping</span><span class="token punctuation">(</span>value <span class="token operator">=</span> <span class="token string">&quot;/request_sentinel4&quot;</span><span class="token punctuation">)</span>
<span class="token annotation punctuation">@SentinelResource</span><span class="token punctuation">(</span><span class="token string">&quot;request_sentinel4&quot;</span><span class="token punctuation">)</span>
<span class="token keyword">public</span> <span class="token class-name">String</span> <span class="token function">requestSentinel4</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
    log<span class="token punctuation">.</span><span class="token function">info</span><span class="token punctuation">(</span><span class="token string">&quot;测试Sentinel4&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    count<span class="token operator">++</span><span class="token punctuation">;</span>
    <span class="token comment">//模拟异常，比例为50%</span>
    <span class="token keyword">if</span> <span class="token punctuation">(</span>count <span class="token operator">%</span> <span class="token number">2</span> <span class="token operator">==</span> <span class="token number">0</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
        <span class="token keyword">throw</span> <span class="token keyword">new</span> <span class="token class-name">RuntimeException</span><span class="token punctuation">(</span><span class="token string">&quot;演示基于异常比例熔断&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    <span class="token keyword">return</span> <span class="token string">&quot;sentinel4&quot;</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br></div></div><p>（2）首先在浏览器中访问<code>http://localhost:8080/order/request_sentinel4</code>，在Sentinel的簇点链路里找到/request_sentinel4。</p> <p><img alt="sa-2022-05-05-034" data-src="https://binghe001.github.io/assets/images/microservices/springcloudalibaba/sa-2022-05-05-034.png" loading="lazy" class="lazy"></p> <p>（3）点击熔断按钮，进入熔断规则配置框，按照如下方式进行配置。</p> <p><img alt="sa-2022-05-05-035" data-src="https://binghe001.github.io/assets/images/microservices/springcloudalibaba/sa-2022-05-05-035.png" loading="lazy" class="lazy"></p> <p>在<code>io.binghe.shop.order.controller.SentinelController#requestSentinel4()</code>方法中，设置的异常比例为50%，这里在Sentinel的比例阈值中设置的异常比例为0.3，也就是30%，所以，在访问<code>http://localhost:8080/order/request_sentinel4</code>接口时，会触发Sentinel的熔断操作。</p> <p>（4）点击新增按钮后，不断在浏览器中刷新<code>http://localhost:8080/order/request_sentinel4</code>，会发现触发了Sentinel的熔断操作，如下所示。</p> <p><img alt="sa-2022-05-05-036" data-src="https://binghe001.github.io/assets/images/microservices/springcloudalibaba/sa-2022-05-05-036.png" loading="lazy" class="lazy"></p> <h3 id="演示基于异常数熔断"><a href="#演示基于异常数熔断" class="header-anchor">#</a> 演示基于异常数熔断</h3> <p>（1）首先在浏览器中访问<code>http://localhost:8080/order/request_sentinel4</code>，在Sentinel的簇点链路里找到/request_sentinel4。</p> <p><img alt="sa-2022-05-05-034" data-src="https://binghe001.github.io/assets/images/microservices/springcloudalibaba/sa-2022-05-05-034.png" loading="lazy" class="lazy"></p> <p>（2）点击熔断按钮，进入熔断规则配置框，按照如下方式进行配置。</p> <p><img alt="sa-2022-05-05-037" data-src="https://binghe001.github.io/assets/images/microservices/springcloudalibaba/sa-2022-05-05-037.png" loading="lazy" class="lazy"></p> <p>上述配置表示，在1秒钟内最少请求2次，当异常数大于1时，会触发熔断操作，熔断的时长为5秒。</p> <p>（3）点击保存按钮后，不断在浏览器中刷新<code>http://localhost:8080/order/request_sentinel4</code>，会发现触发了Sentinel的熔断操作，如下所示。</p> <p><img alt="sa-2022-05-05-038" data-src="https://binghe001.github.io/assets/images/microservices/springcloudalibaba/sa-2022-05-05-038.png" loading="lazy" class="lazy"></p> <h2 id="热点规则"><a href="#热点规则" class="header-anchor">#</a> 热点规则</h2> <p>Sentinel的热点规则可以将流量规则控制到具体的参数上。</p> <h3 id="热点规则概述"><a href="#热点规则概述" class="header-anchor">#</a> 热点规则概述</h3> <p>Sentinel的热点规则可以根据具体的参数来控制流量规则，适用于根据不同参数进行流量控制的场景。</p> <h3 id="演示热点规则"><a href="#演示热点规则" class="header-anchor">#</a> 演示热点规则</h3> <p>（1）在订单微服务的<code>io.binghe.shop.order.controller.SentinelController</code>类中新增requestSentinel3()方法，其中会带有一个String类型的参数header和一个String类型的参数body，如下所示。</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token annotation punctuation">@GetMapping</span><span class="token punctuation">(</span>value <span class="token operator">=</span> <span class="token string">&quot;/request_sentinel3&quot;</span><span class="token punctuation">)</span>
<span class="token annotation punctuation">@SentinelResource</span><span class="token punctuation">(</span><span class="token string">&quot;request_sentinel3&quot;</span><span class="token punctuation">)</span>
<span class="token keyword">public</span> <span class="token class-name">String</span> <span class="token function">requestSentinel3</span><span class="token punctuation">(</span><span class="token class-name">String</span> header<span class="token punctuation">,</span> <span class="token class-name">String</span> body<span class="token punctuation">)</span><span class="token punctuation">{</span>
    log<span class="token punctuation">.</span><span class="token function">info</span><span class="token punctuation">(</span><span class="token string">&quot;测试Sentinel3&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token keyword">return</span> <span class="token string">&quot;sentinel3&quot;</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br></div></div><p>（2）在浏览器中访问<code>http://localhost:8080/order/request_sentinel3</code>接口，在Sentinel的簇点链路中会显示/request_sentinel3接口，如下所示。</p> <p><img alt="sa-2022-05-05-022" data-src="https://binghe001.github.io/assets/images/microservices/springcloudalibaba/sa-2022-05-05-022.png" loading="lazy" class="lazy"></p> <p>（3）点击热点按钮，如下所示。</p> <p><img alt="sa-2022-05-05-023" data-src="https://binghe001.github.io/assets/images/microservices/springcloudalibaba/sa-2022-05-05-023.png" loading="lazy" class="lazy"></p> <p>（4）在弹出的热点规则配置框中的参数索引中输入0，单机阈值输入1，统计窗口时长输入1，如下所示。</p> <p><img alt="sa-2022-05-05-024" data-src="https://binghe001.github.io/assets/images/microservices/springcloudalibaba/sa-2022-05-05-024.png" loading="lazy" class="lazy"></p> <p>表示对requestSentinel3()方法的第一个参数header进行限流，如果每秒钟访问的次数超过1次，则触发限流。</p> <p>（5）保存配置后，在浏览器中不断访问<code>http://localhost:8080/order/request_sentinel3?header=header</code>，当每秒访问的频率超过1次时，会触发Sentinel的限流操作，如下所示。</p> <p><img alt="sa-2022-05-05-025" data-src="https://binghe001.github.io/assets/images/microservices/springcloudalibaba/sa-2022-05-05-025.png" loading="lazy" class="lazy"></p> <p>不断访问<code>http://localhost:8080/order/request_sentinel3?body=body</code>，则不会触发限流操作。</p> <p><img alt="sa-2022-05-05-026" data-src="https://binghe001.github.io/assets/images/microservices/springcloudalibaba/sa-2022-05-05-026.png" loading="lazy" class="lazy"></p> <h3 id="演示热点高级选项规则"><a href="#演示热点高级选项规则" class="header-anchor">#</a> 演示热点高级选项规则</h3> <p>（1）在弹出的热点规则配置框中打开高级选项，在参数类型中选择java.lang.String，因为在参数索引中输入0，表示的是对header参数限流，而header参数是String类型的。在参数值里输入header，也就是为参数名为header的参数赋值为字符串header。限流阈值为1，如下所示。</p> <p><img alt="sa-2022-05-05-027" data-src="https://binghe001.github.io/assets/images/microservices/springcloudalibaba/sa-2022-05-05-027.png" loading="lazy" class="lazy"></p> <p>（2）点击添加按钮后如下所示。</p> <p><img alt="sa-2022-05-05-028" data-src="https://binghe001.github.io/assets/images/microservices/springcloudalibaba/sa-2022-05-05-028.png" loading="lazy" class="lazy"></p> <p>（3）点击保存按钮，在浏览器不断刷新<code>http://localhost:8080/order/request_sentinel3?header=header</code>，会触发Sentinel的限流操作。</p> <p><img alt="sa-2022-05-05-029" data-src="https://binghe001.github.io/assets/images/microservices/springcloudalibaba/sa-2022-05-05-029.png" loading="lazy" class="lazy"></p> <h2 id="授权规则"><a href="#授权规则" class="header-anchor">#</a> 授权规则</h2> <p>授权规则能够根据调用来源判断还否允许执行本次请求。</p> <h3 id="授权规则概述"><a href="#授权规则概述" class="header-anchor">#</a> 授权规则概述</h3> <p>在某些场景下，需要根据调用接口的来源判断是否允许执行本次请求。此时就可以使用Sentinel提供的授权规则来实现，Sentinel的授权规则能够根据请求的来源判断是否允许本次请求通过。</p> <p>在Sentinel的授权规则中，提供了 <strong>白名单与黑名单</strong> 两种授权类型。</p> <h3 id="演示授权规则"><a href="#演示授权规则" class="header-anchor">#</a> 演示授权规则</h3> <p>（1）在订单微服务shop-order中新建<code>io.binghe.shop.order.parser</code>包，并创建MyRequestOriginParser类，实现<code>com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.RequestOriginParser</code>接口，用来处理请求的来源。代码如下所示。</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token comment">/**
 * @author binghe
 * @version 1.0.0
 * @description Sentinel授权规则，用来处理请求的来源
 */</span>
<span class="token annotation punctuation">@Component</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">MyRequestOriginParser</span> <span class="token keyword">implements</span> <span class="token class-name">RequestOriginParser</span> <span class="token punctuation">{</span>
    <span class="token annotation punctuation">@Override</span>
    <span class="token keyword">public</span> <span class="token class-name">String</span> <span class="token function">parseOrigin</span><span class="token punctuation">(</span><span class="token class-name">HttpServletRequest</span> httpServletRequest<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">return</span> httpServletRequest<span class="token punctuation">.</span><span class="token function">getParameter</span><span class="token punctuation">(</span><span class="token string">&quot;serverName&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br></div></div><p>（2）首先在浏览器中访问<code>http://localhost:8080/order/request_sentinel4</code>，在Sentinel的簇点链路里找到/request_sentinel4。</p> <p><img alt="sa-2022-05-05-034" data-src="https://binghe001.github.io/assets/images/microservices/springcloudalibaba/sa-2022-05-05-034.png" loading="lazy" class="lazy"></p> <p>（3）点击授权按钮，进入授权规则配置框，按照如下方式进行配置。</p> <p><img alt="sa-2022-05-05-040" data-src="https://binghe001.github.io/assets/images/microservices/springcloudalibaba/sa-2022-05-05-040.png" loading="lazy" class="lazy"></p> <p>其中，流控应用填写的是test，授权类型为黑名单。这里要结合新建的MyRequestOriginParser类进行理解，MyRequestOriginParser类的parseOrigin()方法如下所示。</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token keyword">public</span> <span class="token class-name">String</span> <span class="token function">parseOrigin</span><span class="token punctuation">(</span><span class="token class-name">HttpServletRequest</span> httpServletRequest<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">return</span> httpServletRequest<span class="token punctuation">.</span><span class="token function">getParameter</span><span class="token punctuation">(</span><span class="token string">&quot;serverName&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><p>parseOrigin()方法中直接返回了从HttpServletRequest中获取的serverName参数，而在上图中的流控应用中输出的是test，授权类型为黑名单。</p> <p>所以，如果我们访问<code>http://localhost:8080/order/request_sentinel4?serverName=test</code>的话，是处于黑名单的状态，无法访问。</p> <p>（4）点击新增按钮后，不断在浏览器中刷新<code>http://localhost:8080/order/request_sentinel4?serverName=test</code>，会发现无法访问，被Sentinel限流了。</p> <p><img alt="sa-2022-05-05-041" data-src="https://binghe001.github.io/assets/images/microservices/springcloudalibaba/sa-2022-05-05-041.png" loading="lazy" class="lazy"></p> <h2 id="系统规则"><a href="#系统规则" class="header-anchor">#</a> 系统规则</h2> <p>系统保护规则是从应用级别的入口流量进行控制，从单台机器的总体 Load、 RT、入口 QPS 、 CPU使用率和线程数五个维度监控应用数据，让系统尽可能跑在最大吞吐量的同时保证系统整体的稳定性。</p> <h3 id="系统规则概述"><a href="#系统规则概述" class="header-anchor">#</a> 系统规则概述</h3> <p>系统保护规则是应用整体维度的，而不是资源维度的，并且仅对入口流量 (进入应用的流量) 生效。</p> <ul><li>Load（仅对 Linux/Unix-like 机器生效）：当系统 load1 超过阈值，且系统当前的并发线程数超过系统容量时才会触发系统保护。系统容量由系统的 maxQps * minRt 计算得出。设定参考值一般是 CPU cores * 2.5。</li> <li>RT：当单台机器上所有入口流量的平均 RT 达到阈值即触发系统保护，单位是毫秒。</li> <li>线程数：当单台机器上所有入口流量的并发线程数达到阈值即触发系统保护。</li> <li>入口 QPS：当单台机器上所有入口流量的 QPS 达到阈值即触发系统保护。</li> <li>CPU使用率：当单台机器上所有入口流量的 CPU使用率达到阈值即触发系统保护</li></ul> <h3 id="演示系统规则"><a href="#演示系统规则" class="header-anchor">#</a> 演示系统规则</h3> <p>（1）在订单微服务中新建<code>io.binghe.shop.order.handler</code>包，并创建MyUrlBlockHandler类，实现<code>com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.BlockExceptionHandler</code>接口，用来捕获系统级Sentinel异常，代码如下所示。</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token comment">/**
 * @author binghe
 * @version 1.0.0
 * @description 处理Sentinel系统规则，返回自定义异常
 */</span>
<span class="token annotation punctuation">@Component</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">MyUrlBlockHandler</span> <span class="token keyword">implements</span> <span class="token class-name">BlockExceptionHandler</span> <span class="token punctuation">{</span>
    <span class="token annotation punctuation">@Override</span>
    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">handle</span><span class="token punctuation">(</span><span class="token class-name">HttpServletRequest</span> request<span class="token punctuation">,</span> <span class="token class-name">HttpServletResponse</span> response<span class="token punctuation">,</span> <span class="token class-name">BlockException</span> e<span class="token punctuation">)</span> <span class="token keyword">throws</span> <span class="token class-name">Exception</span> <span class="token punctuation">{</span>
        <span class="token class-name">String</span> msg <span class="token operator">=</span> <span class="token keyword">null</span><span class="token punctuation">;</span>
        <span class="token keyword">if</span> <span class="token punctuation">(</span>e <span class="token keyword">instanceof</span> <span class="token class-name">FlowException</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            msg <span class="token operator">=</span> <span class="token string">&quot;限流了&quot;</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token keyword">if</span> <span class="token punctuation">(</span>e <span class="token keyword">instanceof</span> <span class="token class-name">DegradeException</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            msg <span class="token operator">=</span> <span class="token string">&quot;降级了&quot;</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token keyword">if</span> <span class="token punctuation">(</span>e <span class="token keyword">instanceof</span> <span class="token class-name">ParamFlowException</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            msg <span class="token operator">=</span> <span class="token string">&quot;热点参数限流&quot;</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token keyword">if</span> <span class="token punctuation">(</span>e <span class="token keyword">instanceof</span> <span class="token class-name">SystemBlockException</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            msg <span class="token operator">=</span> <span class="token string">&quot;系统规则（负载/...不满足要求）&quot;</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token keyword">if</span> <span class="token punctuation">(</span>e <span class="token keyword">instanceof</span> <span class="token class-name">AuthorityException</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            msg <span class="token operator">=</span> <span class="token string">&quot;授权规则不通过&quot;</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
        <span class="token comment">// http状态码</span>
        response<span class="token punctuation">.</span><span class="token function">setStatus</span><span class="token punctuation">(</span><span class="token number">500</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        response<span class="token punctuation">.</span><span class="token function">setCharacterEncoding</span><span class="token punctuation">(</span><span class="token string">&quot;utf-8&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        response<span class="token punctuation">.</span><span class="token function">setHeader</span><span class="token punctuation">(</span><span class="token string">&quot;Content-Type&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;application/json;charset=utf-8&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        response<span class="token punctuation">.</span><span class="token function">setContentType</span><span class="token punctuation">(</span><span class="token string">&quot;application/json;charset=utf-8&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">JSONObject</span> jsonObject <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">JSONObject</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        jsonObject<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token string">&quot;code&quot;</span><span class="token punctuation">,</span> <span class="token number">500</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        jsonObject<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token string">&quot;codeMsg&quot;</span><span class="token punctuation">,</span> msg<span class="token punctuation">)</span><span class="token punctuation">;</span>
        response<span class="token punctuation">.</span><span class="token function">getWriter</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">write</span><span class="token punctuation">(</span>jsonObject<span class="token punctuation">.</span><span class="token function">toJSONString</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br><span class="line-number">32</span><br></div></div><p>（2）在订单微服务的<code>io.binghe.shop.order.controller.SentinelController</code>类中新增requestSentinel5()方法，如下所示。</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token annotation punctuation">@GetMapping</span><span class="token punctuation">(</span>value <span class="token operator">=</span> <span class="token string">&quot;/request_sentinel5&quot;</span><span class="token punctuation">)</span>
<span class="token annotation punctuation">@SentinelResource</span><span class="token punctuation">(</span><span class="token string">&quot;request_sentinel5&quot;</span><span class="token punctuation">)</span>
<span class="token keyword">public</span> <span class="token class-name">String</span> <span class="token function">requestSentinel5</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
    log<span class="token punctuation">.</span><span class="token function">info</span><span class="token punctuation">(</span><span class="token string">&quot;测试Sentinel5&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token keyword">return</span> <span class="token string">&quot;sentinel5&quot;</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br></div></div><p>（3）首先在浏览器中访问<code>http://localhost:8080/order/request_sentinel5</code>，在Sentinel的簇点链路里找到/request_sentinel5。</p> <p><img alt="sa-2022-05-05-034" data-src="https://binghe001.github.io/assets/images/microservices/springcloudalibaba/sa-2022-05-05-043.png" loading="lazy" class="lazy"></p> <p>（4）点击流控按钮，进入流控规则配置框，按照如下方式进行配置。</p> <p><img alt="sa-2022-05-05-042" data-src="https://binghe001.github.io/assets/images/microservices/springcloudalibaba/sa-2022-05-05-042.png" loading="lazy" class="lazy"></p> <p>（5）在浏览器中不断刷新<code>http://localhost:8080/order/request_sentinel5</code>，会显示如下信息。</p> <p><img alt="sa-2022-05-05-044" data-src="https://binghe001.github.io/assets/images/microservices/springcloudalibaba/sa-2022-05-05-044.png" loading="lazy" class="lazy"></p> <p>返回的原始数据如下所示。</p> <div class="language-json line-numbers-mode"><pre class="language-json"><code><span class="token punctuation">{</span><span class="token property">&quot;code&quot;</span><span class="token operator">:</span><span class="token number">500</span><span class="token punctuation">,</span><span class="token property">&quot;codeMsg&quot;</span><span class="token operator">:</span><span class="token string">&quot;限流了&quot;</span><span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>说明触发了系统规则，捕获到了Sentinel全局异常。</p> <h2 id="sentinelresource注解"><a href="#sentinelresource注解" class="header-anchor">#</a> @SentinelResource注解</h2> <p>使用Sentinel时，可以使用@SentinelResource注解来指定异常处理策略。</p> <h3 id="sentinelresource注解概述"><a href="#sentinelresource注解概述" class="header-anchor">#</a> @SentinelResource注解概述</h3> <p>在Sentinel中，指定发生异常时的处理策略非常简单，只需要使用@SentinelResource注解即可，@SentinelResource注解的源码如下所示。</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token annotation punctuation">@Target</span><span class="token punctuation">(</span><span class="token punctuation">{</span><span class="token class-name">ElementType</span><span class="token punctuation">.</span>METHOD<span class="token punctuation">,</span> <span class="token class-name">ElementType</span><span class="token punctuation">.</span>TYPE<span class="token punctuation">}</span><span class="token punctuation">)</span>
<span class="token annotation punctuation">@Retention</span><span class="token punctuation">(</span><span class="token class-name">RetentionPolicy</span><span class="token punctuation">.</span>RUNTIME<span class="token punctuation">)</span>
<span class="token annotation punctuation">@Inherited</span>
<span class="token keyword">public</span> <span class="token annotation punctuation">@interface</span> <span class="token class-name">SentinelResource</span> <span class="token punctuation">{</span>

	<span class="token comment">//资源名称</span>
    <span class="token class-name">String</span> <span class="token function">value</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token keyword">default</span> <span class="token string">&quot;&quot;</span><span class="token punctuation">;</span>
	<span class="token comment">//entry类型，标记流量的方向，取值IN/OUT，默认是OUT</span>
    <span class="token class-name">EntryType</span> <span class="token function">entryType</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token keyword">default</span> <span class="token class-name">EntryType</span><span class="token punctuation">.</span>OUT<span class="token punctuation">;</span>
    <span class="token keyword">int</span> <span class="token function">resourceType</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token keyword">default</span> <span class="token number">0</span><span class="token punctuation">;</span>
	<span class="token comment">//处理BlockException的函数名称,函数要求：</span>
    <span class="token comment">//1. 必须是 public</span>
    <span class="token comment">//2.返回类型 参数与原方法一致</span>
    <span class="token comment">//3. 默认需和原方法在同一个类中。若希望使用其他类的函数，可配置</span>
    <span class="token comment">//blockHandlerClass ，并指定blockHandlerClass里面的方法。</span>
    <span class="token class-name">String</span> <span class="token function">blockHandler</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token keyword">default</span> <span class="token string">&quot;&quot;</span><span class="token punctuation">;</span>
	
    <span class="token comment">//存放blockHandler的类,对应的处理函数必须static修饰。</span>
    <span class="token class-name">Class</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token operator">?</span><span class="token punctuation">&gt;</span></span><span class="token punctuation">[</span><span class="token punctuation">]</span> <span class="token function">blockHandlerClass</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token keyword">default</span> <span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">;</span>
	
    <span class="token comment">//用于在抛出异常的时候提供fallback处理逻辑。 fallback函数可以针对所</span>
    <span class="token comment">//有类型的异常（除了 exceptionsToIgnore 里面排除掉的异常类型）进行处理。函数要求：</span>
    <span class="token comment">//1. 返回类型与原方法一致</span>
    <span class="token comment">//2. 参数类型需要和原方法相匹配</span>
    <span class="token comment">//3. 默认需和原方法在同一个类中。若希望使用其他类的函数，可配置fallbackClass ，并指定fallbackClass里面的方法。</span>
    <span class="token class-name">String</span> <span class="token function">fallback</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token keyword">default</span> <span class="token string">&quot;&quot;</span><span class="token punctuation">;</span>
	
    <span class="token comment">//存放fallback的类。对应的处理函数必须static修饰。</span>
    <span class="token class-name">String</span> <span class="token function">defaultFallback</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token keyword">default</span> <span class="token string">&quot;&quot;</span><span class="token punctuation">;</span>

	<span class="token comment">//用于通用的 fallback 逻辑。默认fallback函数可以针对所有类型的异常进</span>
    <span class="token comment">//行处理。若同时配置了 fallback 和 defaultFallback，以fallback为准。函数要求：</span>
    <span class="token comment">//1. 返回类型与原方法一致</span>
    <span class="token comment">//2. 方法参数列表为空，或者有一个 Throwable 类型的参数。</span>
    <span class="token comment">//3. 默认需要和原方法在同一个类中。若希望使用其他类的函数，可配置fallbackClass ，并指定 fallbackClass 里面的方法。</span>
    <span class="token class-name">Class</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token operator">?</span><span class="token punctuation">&gt;</span></span><span class="token punctuation">[</span><span class="token punctuation">]</span> <span class="token function">fallbackClass</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token keyword">default</span> <span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">;</span>

  	<span class="token comment">//指定排除掉哪些异常。排除的异常不会计入异常统计，也不会进入fallback逻辑，而是原样抛出。</span>
    <span class="token class-name">Class</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token operator">?</span> <span class="token keyword">extends</span> <span class="token class-name">Throwable</span><span class="token punctuation">&gt;</span></span><span class="token punctuation">[</span><span class="token punctuation">]</span> <span class="token function">exceptionsToTrace</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token keyword">default</span> <span class="token punctuation">{</span><span class="token class-name">Throwable</span><span class="token punctuation">.</span><span class="token keyword">class</span><span class="token punctuation">}</span><span class="token punctuation">;</span>
    
	<span class="token comment">//需要trace的异常</span>
    <span class="token class-name">Class</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token operator">?</span> <span class="token keyword">extends</span> <span class="token class-name">Throwable</span><span class="token punctuation">&gt;</span></span><span class="token punctuation">[</span><span class="token punctuation">]</span> <span class="token function">exceptionsToIgnore</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token keyword">default</span> <span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br><span class="line-number">32</span><br><span class="line-number">33</span><br><span class="line-number">34</span><br><span class="line-number">35</span><br><span class="line-number">36</span><br><span class="line-number">37</span><br><span class="line-number">38</span><br><span class="line-number">39</span><br><span class="line-number">40</span><br><span class="line-number">41</span><br><span class="line-number">42</span><br><span class="line-number">43</span><br></div></div><h3 id="演示-sentinelresource注解"><a href="#演示-sentinelresource注解" class="header-anchor">#</a> 演示@SentinelResource注解</h3> <p><strong>1.定义限流和降级后的处理方法</strong></p> <p>（1）在订单微服务的<code>io.binghe.shop.order.service.SentinelService</code>接口中新增sendMessage2()方法，如下所示。</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token class-name">String</span> <span class="token function">sendMessage2</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>（2）在订单微服务的<code>io.binghe.shop.order.service.impl.SentinelServiceImpl</code>方法中，实现sendMessage2()方法，并且定义一个成员变量count，用来记录请求sendMessage2()方法的次数，同时定义25%的异常率。在sendMessage2()方法上使用@SentinelResource指定了资源的名称、发生BlockException时进入的方法和发生异常时进入的方法，代码如下所示。</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token keyword">private</span> <span class="token keyword">int</span> count <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span>

<span class="token annotation punctuation">@Override</span>
<span class="token annotation punctuation">@SentinelResource</span><span class="token punctuation">(</span>
    value <span class="token operator">=</span> <span class="token string">&quot;sendMessage2&quot;</span><span class="token punctuation">,</span>
    blockHandler <span class="token operator">=</span> <span class="token string">&quot;blockHandler&quot;</span><span class="token punctuation">,</span>
    fallback <span class="token operator">=</span> <span class="token string">&quot;fallback&quot;</span><span class="token punctuation">)</span>
<span class="token keyword">public</span> <span class="token class-name">String</span> <span class="token function">sendMessage2</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    count <span class="token operator">++</span><span class="token punctuation">;</span>
    <span class="token comment">//25%的异常率</span>
    <span class="token keyword">if</span> <span class="token punctuation">(</span>count <span class="token operator">%</span> <span class="token number">4</span> <span class="token operator">==</span> <span class="token number">0</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
        <span class="token keyword">throw</span> <span class="token keyword">new</span> <span class="token class-name">RuntimeException</span><span class="token punctuation">(</span><span class="token string">&quot;25%的异常率&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    <span class="token keyword">return</span> <span class="token string">&quot;sendMessage2&quot;</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>

<span class="token keyword">public</span> <span class="token class-name">String</span> <span class="token function">blockHandler</span><span class="token punctuation">(</span><span class="token class-name">BlockException</span> e<span class="token punctuation">)</span><span class="token punctuation">{</span>
    log<span class="token punctuation">.</span><span class="token function">error</span><span class="token punctuation">(</span><span class="token string">&quot;限流了:{}&quot;</span><span class="token punctuation">,</span> e<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token keyword">return</span> <span class="token string">&quot;限流了&quot;</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>

<span class="token keyword">public</span> <span class="token class-name">String</span> <span class="token function">fallback</span><span class="token punctuation">(</span><span class="token class-name">Throwable</span> e<span class="token punctuation">)</span><span class="token punctuation">{</span>
    log<span class="token punctuation">.</span><span class="token function">error</span><span class="token punctuation">(</span><span class="token string">&quot;异常了:{}&quot;</span><span class="token punctuation">,</span> e<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token keyword">return</span> <span class="token string">&quot;异常了&quot;</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br></div></div><p>（3）在订单微服务的<code>io.binghe.shop.order.controller.SentinelController</code>类中新增requestSentinel6()方法，在方法中调用<code>io.binghe.shop.order.service.SentinelService</code>接口中的sendMessage2()方法，如下所示。</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token annotation punctuation">@GetMapping</span><span class="token punctuation">(</span>value <span class="token operator">=</span> <span class="token string">&quot;/request_sentinel6&quot;</span><span class="token punctuation">)</span>
<span class="token keyword">public</span> <span class="token class-name">String</span> <span class="token function">requestSentinel6</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
    log<span class="token punctuation">.</span><span class="token function">info</span><span class="token punctuation">(</span><span class="token string">&quot;测试Sentinel6&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token keyword">return</span> sentinelService<span class="token punctuation">.</span><span class="token function">sendMessage2</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><p>（4）首先在浏览器中访问<code>http://localhost:8080/order/request_sentinel6</code>，在Sentinel的簇点链路里找到/request_sentinel6。</p> <p><img alt="sa-2022-05-05-045" data-src="https://binghe001.github.io/assets/images/microservices/springcloudalibaba/sa-2022-05-05-045.png" loading="lazy" class="lazy"></p> <p>（5）点击流控按钮进入流控规则页面，按照下图方式进行配置。</p> <p><img alt="sa-2022-05-05-046" data-src="https://binghe001.github.io/assets/images/microservices/springcloudalibaba/sa-2022-05-05-046.png" loading="lazy" class="lazy"></p> <p>（6）点击新增按钮后在浏览器中刷新<code>http://localhost:8080/order/request_sentinel6</code>，当刷新的频率超过每秒2次时，浏览器会显示如下信息。</p> <p><img alt="sa-2022-05-05-048" data-src="https://binghe001.github.io/assets/images/microservices/springcloudalibaba/sa-2022-05-05-048.png" loading="lazy" class="lazy"></p> <p>当刷新的次数是4的倍数时，浏览器会显示如下信息。</p> <p><img alt="sa-2022-05-05-047" data-src="https://binghe001.github.io/assets/images/microservices/springcloudalibaba/sa-2022-05-05-047.png" loading="lazy" class="lazy"></p> <p><strong>2.在外部类中指定限流和异常调用的方法</strong></p> <p>（1）在订单微服务的<code>io.binghe.shop.order.handler</code>包下新建MyBlockHandlerClass类，用于定义被Sentinel限流时的方法，源码如下所示。</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token comment">/**
 * @author binghe
 * @version 1.0.0
 * @description 定义被Sentinel限流时调用的方法
 */</span>
<span class="token annotation punctuation">@Slf4j</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">MyBlockHandlerClass</span> <span class="token punctuation">{</span>

    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token class-name">String</span> <span class="token function">blockHandler</span><span class="token punctuation">(</span><span class="token class-name">BlockException</span> e<span class="token punctuation">)</span><span class="token punctuation">{</span>
        log<span class="token punctuation">.</span><span class="token function">error</span><span class="token punctuation">(</span><span class="token string">&quot;限流了:{}&quot;</span><span class="token punctuation">,</span> e<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">return</span> <span class="token string">&quot;限流了&quot;</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br></div></div><p>（2）在订单微服务的<code>io.binghe.shop.order.handler</code>包下新建MyFallbackClass类，用于定义抛出异常时调用的方法，源码如下所示。</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token comment">/**
 * @author binghe
 * @version 1.0.0
 * @description 定义异常时调用的方法
 */</span>
<span class="token annotation punctuation">@Slf4j</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">MyFallbackClass</span> <span class="token punctuation">{</span>

    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token class-name">String</span> <span class="token function">fallback</span><span class="token punctuation">(</span><span class="token class-name">Throwable</span> e<span class="token punctuation">)</span><span class="token punctuation">{</span>
        log<span class="token punctuation">.</span><span class="token function">error</span><span class="token punctuation">(</span><span class="token string">&quot;异常了:{}&quot;</span><span class="token punctuation">,</span> e<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">return</span> <span class="token string">&quot;异常了&quot;</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br></div></div><p>（3）修改<code>io.binghe.shop.order.service.impl.SentinelServiceImpl#sendMessage2()</code>方法上的注解，修改后的代码如下所示。</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token annotation punctuation">@Override</span>
<span class="token annotation punctuation">@SentinelResource</span><span class="token punctuation">(</span>
    value <span class="token operator">=</span> <span class="token string">&quot;sendMessage2&quot;</span><span class="token punctuation">,</span>
    blockHandlerClass <span class="token operator">=</span> <span class="token class-name">MyBlockHandlerClass</span><span class="token punctuation">.</span><span class="token keyword">class</span><span class="token punctuation">,</span>
    blockHandler <span class="token operator">=</span> <span class="token string">&quot;blockHandler&quot;</span><span class="token punctuation">,</span>
    fallbackClass <span class="token operator">=</span> <span class="token class-name">MyFallbackClass</span><span class="token punctuation">.</span><span class="token keyword">class</span><span class="token punctuation">,</span>
    fallback <span class="token operator">=</span> <span class="token string">&quot;fallback&quot;</span><span class="token punctuation">)</span>
<span class="token keyword">public</span> <span class="token class-name">String</span> <span class="token function">sendMessage2</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    count <span class="token operator">++</span><span class="token punctuation">;</span>
    <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>count<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token comment">//25%的异常率</span>
    <span class="token keyword">if</span> <span class="token punctuation">(</span>count <span class="token operator">%</span> <span class="token number">4</span> <span class="token operator">==</span> <span class="token number">0</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
        <span class="token keyword">throw</span> <span class="token keyword">new</span> <span class="token class-name">RuntimeException</span><span class="token punctuation">(</span><span class="token string">&quot;25%的异常率&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    <span class="token keyword">return</span> <span class="token string">&quot;sendMessage2&quot;</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br></div></div><p>（4）首先在浏览器中访问<code>http://localhost:8080/order/request_sentinel6</code>，在Sentinel的簇点链路里找到/request_sentinel6。</p> <p><img alt="sa-2022-05-05-045" data-src="https://binghe001.github.io/assets/images/microservices/springcloudalibaba/sa-2022-05-05-045.png" loading="lazy" class="lazy"></p> <p>（5）点击流控按钮进入流控规则页面，按照下图方式进行配置。</p> <p><img alt="sa-2022-05-05-046" data-src="https://binghe001.github.io/assets/images/microservices/springcloudalibaba/sa-2022-05-05-046.png" loading="lazy" class="lazy"></p> <p>（6）点击新增按钮后在浏览器中刷新<code>http://localhost:8080/order/request_sentinel6</code>，当刷新的频率超过每秒2次时，浏览器会显示如下信息。</p> <p><img alt="sa-2022-05-05-048" data-src="https://binghe001.github.io/assets/images/microservices/springcloudalibaba/sa-2022-05-05-048.png" loading="lazy" class="lazy"></p> <p>当刷新的次数是4的倍数时，浏览器会显示如下信息。</p> <p><img alt="sa-2022-05-05-047" data-src="https://binghe001.github.io/assets/images/microservices/springcloudalibaba/sa-2022-05-05-047.png" loading="lazy" class="lazy"></p> <h2 id="sentinel持久化"><a href="#sentinel持久化" class="header-anchor">#</a> Sentinel持久化</h2> <p>Sentinel中可以自定义配置的持久化来将Sentinel的配置规则持久化到服务器磁盘，使得重启应用或者Sentinel后，Sentinel的配置规则不丢失。</p> <h3 id="sentinel持久化概述"><a href="#sentinel持久化概述" class="header-anchor">#</a> Sentinel持久化概述</h3> <p>细心的小伙伴会发现，我们之前配置的Sentinel规则在程序重启或者Sentinel重启后就会消失不见，此时就需要我们重新配置。如果这发生在高并发、大流量的场景下是不可接受的。那有没有什么办法让程序或Sentinel重启后配置不丢失呢？其实，Sentinel中可以自定义配置的持久化来解决这个问题。</p> <h3 id="实现sentinel的持久化"><a href="#实现sentinel的持久化" class="header-anchor">#</a> 实现Sentinel的持久化</h3> <p>（1）在订单微服务shop-order中新建<code>io.binghe.shop.order.persistence</code>包，并创建SentinelPersistenceRule类，实现<code>com.alibaba.csp.sentinel.init.InitFunc</code>接口，并在SentinelPersistenceRule类中获取应用的名称，覆写init()方法，源码如下所示。</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token comment">/**
 * @author binghe
 * @version 1.0.0
 * @description Sentinel规则持久化
 */</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">SentinelPersistenceRule</span> <span class="token keyword">implements</span> <span class="token class-name">InitFunc</span> <span class="token punctuation">{</span>
    <span class="token comment">//实际可以从外部配置读取</span>
    <span class="token keyword">private</span> <span class="token class-name">String</span> appcationName <span class="token operator">=</span> <span class="token string">&quot;server-order&quot;</span><span class="token punctuation">;</span>
    <span class="token annotation punctuation">@Override</span>
    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">init</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token keyword">throws</span> <span class="token class-name">Exception</span> <span class="token punctuation">{</span>
        <span class="token class-name">String</span> ruleDir <span class="token operator">=</span> <span class="token class-name">System</span><span class="token punctuation">.</span><span class="token function">getProperty</span><span class="token punctuation">(</span><span class="token string">&quot;user.home&quot;</span><span class="token punctuation">)</span> <span class="token operator">+</span> <span class="token string">&quot;/sentinel-rules/&quot;</span> <span class="token operator">+</span> appcationName<span class="token punctuation">;</span>
        <span class="token class-name">String</span> flowRulePath <span class="token operator">=</span> ruleDir <span class="token operator">+</span> <span class="token string">&quot;/flow-rule.json&quot;</span><span class="token punctuation">;</span>
        <span class="token class-name">String</span> degradeRulePath <span class="token operator">=</span> ruleDir <span class="token operator">+</span> <span class="token string">&quot;/degrade-rule.json&quot;</span><span class="token punctuation">;</span>
        <span class="token class-name">String</span> systemRulePath <span class="token operator">=</span> ruleDir <span class="token operator">+</span> <span class="token string">&quot;/system-rule.json&quot;</span><span class="token punctuation">;</span>
        <span class="token class-name">String</span> authorityRulePath <span class="token operator">=</span> ruleDir <span class="token operator">+</span> <span class="token string">&quot;/authority-rule.json&quot;</span><span class="token punctuation">;</span>
        <span class="token class-name">String</span> paramFlowRulePath <span class="token operator">=</span> ruleDir <span class="token operator">+</span> <span class="token string">&quot;/param-flow-rule.json&quot;</span><span class="token punctuation">;</span>

        <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">mkdirIfNotExits</span><span class="token punctuation">(</span>ruleDir<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">createFileIfNotExits</span><span class="token punctuation">(</span>flowRulePath<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">createFileIfNotExits</span><span class="token punctuation">(</span>degradeRulePath<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">createFileIfNotExits</span><span class="token punctuation">(</span>systemRulePath<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">createFileIfNotExits</span><span class="token punctuation">(</span>authorityRulePath<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">createFileIfNotExits</span><span class="token punctuation">(</span>paramFlowRulePath<span class="token punctuation">)</span><span class="token punctuation">;</span>

        <span class="token comment">// 流控规则</span>
        <span class="token class-name">ReadableDataSource</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">String</span><span class="token punctuation">,</span> <span class="token class-name">List</span><span class="token punctuation">&lt;</span><span class="token class-name">FlowRule</span><span class="token punctuation">&gt;</span><span class="token punctuation">&gt;</span></span> flowRuleRDS <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">FileRefreshableDataSource</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token punctuation">&gt;</span></span><span class="token punctuation">(</span>
                flowRulePath<span class="token punctuation">,</span>
                flowRuleListParser
        <span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">FlowRuleManager</span><span class="token punctuation">.</span><span class="token function">register2Property</span><span class="token punctuation">(</span>flowRuleRDS<span class="token punctuation">.</span><span class="token function">getProperty</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">WritableDataSource</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">List</span><span class="token punctuation">&lt;</span><span class="token class-name">FlowRule</span><span class="token punctuation">&gt;</span><span class="token punctuation">&gt;</span></span> flowRuleWDS <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">FileWritableDataSource</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token punctuation">&gt;</span></span><span class="token punctuation">(</span>
                flowRulePath<span class="token punctuation">,</span>
                <span class="token keyword">this</span><span class="token operator">::</span><span class="token function">encodeJson</span>
        <span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">WritableDataSourceRegistry</span><span class="token punctuation">.</span><span class="token function">registerFlowDataSource</span><span class="token punctuation">(</span>flowRuleWDS<span class="token punctuation">)</span><span class="token punctuation">;</span>

        <span class="token comment">// 降级规则</span>
        <span class="token class-name">ReadableDataSource</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">String</span><span class="token punctuation">,</span> <span class="token class-name">List</span><span class="token punctuation">&lt;</span><span class="token class-name">DegradeRule</span><span class="token punctuation">&gt;</span><span class="token punctuation">&gt;</span></span> degradeRuleRDS <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">FileRefreshableDataSource</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token punctuation">&gt;</span></span><span class="token punctuation">(</span>
                degradeRulePath<span class="token punctuation">,</span>
                degradeRuleListParser
        <span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">DegradeRuleManager</span><span class="token punctuation">.</span><span class="token function">register2Property</span><span class="token punctuation">(</span>degradeRuleRDS<span class="token punctuation">.</span><span class="token function">getProperty</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">WritableDataSource</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">List</span><span class="token punctuation">&lt;</span><span class="token class-name">DegradeRule</span><span class="token punctuation">&gt;</span><span class="token punctuation">&gt;</span></span> degradeRuleWDS <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">FileWritableDataSource</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token punctuation">&gt;</span></span><span class="token punctuation">(</span>
                degradeRulePath<span class="token punctuation">,</span>
                <span class="token keyword">this</span><span class="token operator">::</span><span class="token function">encodeJson</span>
        <span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">WritableDataSourceRegistry</span><span class="token punctuation">.</span><span class="token function">registerDegradeDataSource</span><span class="token punctuation">(</span>degradeRuleWDS<span class="token punctuation">)</span><span class="token punctuation">;</span>

        <span class="token comment">// 系统规则</span>
        <span class="token class-name">ReadableDataSource</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">String</span><span class="token punctuation">,</span> <span class="token class-name">List</span><span class="token punctuation">&lt;</span><span class="token class-name">SystemRule</span><span class="token punctuation">&gt;</span><span class="token punctuation">&gt;</span></span> systemRuleRDS <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">FileRefreshableDataSource</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token punctuation">&gt;</span></span><span class="token punctuation">(</span>
                systemRulePath<span class="token punctuation">,</span>
                systemRuleListParser
        <span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">SystemRuleManager</span><span class="token punctuation">.</span><span class="token function">register2Property</span><span class="token punctuation">(</span>systemRuleRDS<span class="token punctuation">.</span><span class="token function">getProperty</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">WritableDataSource</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">List</span><span class="token punctuation">&lt;</span><span class="token class-name">SystemRule</span><span class="token punctuation">&gt;</span><span class="token punctuation">&gt;</span></span> systemRuleWDS <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">FileWritableDataSource</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token punctuation">&gt;</span></span><span class="token punctuation">(</span>
                systemRulePath<span class="token punctuation">,</span>
                <span class="token keyword">this</span><span class="token operator">::</span><span class="token function">encodeJson</span>
        <span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">WritableDataSourceRegistry</span><span class="token punctuation">.</span><span class="token function">registerSystemDataSource</span><span class="token punctuation">(</span>systemRuleWDS<span class="token punctuation">)</span><span class="token punctuation">;</span>

        <span class="token comment">// 授权规则</span>
        <span class="token class-name">ReadableDataSource</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">String</span><span class="token punctuation">,</span> <span class="token class-name">List</span><span class="token punctuation">&lt;</span><span class="token class-name">AuthorityRule</span><span class="token punctuation">&gt;</span><span class="token punctuation">&gt;</span></span> authorityRuleRDS <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">FileRefreshableDataSource</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token punctuation">&gt;</span></span><span class="token punctuation">(</span>
                authorityRulePath<span class="token punctuation">,</span>
                authorityRuleListParser
        <span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">AuthorityRuleManager</span><span class="token punctuation">.</span><span class="token function">register2Property</span><span class="token punctuation">(</span>authorityRuleRDS<span class="token punctuation">.</span><span class="token function">getProperty</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">WritableDataSource</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">List</span><span class="token punctuation">&lt;</span><span class="token class-name">AuthorityRule</span><span class="token punctuation">&gt;</span><span class="token punctuation">&gt;</span></span> authorityRuleWDS <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">FileWritableDataSource</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token punctuation">&gt;</span></span><span class="token punctuation">(</span>
                authorityRulePath<span class="token punctuation">,</span>
                <span class="token keyword">this</span><span class="token operator">::</span><span class="token function">encodeJson</span>
        <span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">WritableDataSourceRegistry</span><span class="token punctuation">.</span><span class="token function">registerAuthorityDataSource</span><span class="token punctuation">(</span>authorityRuleWDS<span class="token punctuation">)</span><span class="token punctuation">;</span>

        <span class="token comment">// 热点参数规则</span>
        <span class="token class-name">ReadableDataSource</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">String</span><span class="token punctuation">,</span> <span class="token class-name">List</span><span class="token punctuation">&lt;</span><span class="token class-name">ParamFlowRule</span><span class="token punctuation">&gt;</span><span class="token punctuation">&gt;</span></span> paramFlowRuleRDS <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">FileRefreshableDataSource</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token punctuation">&gt;</span></span><span class="token punctuation">(</span>
                paramFlowRulePath<span class="token punctuation">,</span>
                paramFlowRuleListParser
        <span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">ParamFlowRuleManager</span><span class="token punctuation">.</span><span class="token function">register2Property</span><span class="token punctuation">(</span>paramFlowRuleRDS<span class="token punctuation">.</span><span class="token function">getProperty</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">WritableDataSource</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">List</span><span class="token punctuation">&lt;</span><span class="token class-name">ParamFlowRule</span><span class="token punctuation">&gt;</span><span class="token punctuation">&gt;</span></span> paramFlowRuleWDS <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">FileWritableDataSource</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token punctuation">&gt;</span></span><span class="token punctuation">(</span>
                paramFlowRulePath<span class="token punctuation">,</span>
                <span class="token keyword">this</span><span class="token operator">::</span><span class="token function">encodeJson</span>
        <span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">ModifyParamFlowRulesCommandHandler</span><span class="token punctuation">.</span><span class="token function">setWritableDataSource</span><span class="token punctuation">(</span>paramFlowRuleWDS<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">private</span> <span class="token class-name">Converter</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">String</span><span class="token punctuation">,</span> <span class="token class-name">List</span><span class="token punctuation">&lt;</span><span class="token class-name">FlowRule</span><span class="token punctuation">&gt;</span><span class="token punctuation">&gt;</span></span> flowRuleListParser <span class="token operator">=</span> source <span class="token operator">-&gt;</span> JSON<span class="token punctuation">.</span><span class="token function">parseObject</span><span class="token punctuation">(</span>
            source<span class="token punctuation">,</span>
            <span class="token keyword">new</span> <span class="token class-name">TypeReference</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">List</span><span class="token punctuation">&lt;</span><span class="token class-name">FlowRule</span><span class="token punctuation">&gt;</span><span class="token punctuation">&gt;</span></span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token punctuation">}</span>
    <span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token keyword">private</span> <span class="token class-name">Converter</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">String</span><span class="token punctuation">,</span> <span class="token class-name">List</span><span class="token punctuation">&lt;</span><span class="token class-name">DegradeRule</span><span class="token punctuation">&gt;</span><span class="token punctuation">&gt;</span></span> degradeRuleListParser <span class="token operator">=</span> source <span class="token operator">-&gt;</span> JSON<span class="token punctuation">.</span><span class="token function">parseObject</span><span class="token punctuation">(</span>
            source<span class="token punctuation">,</span>
            <span class="token keyword">new</span> <span class="token class-name">TypeReference</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">List</span><span class="token punctuation">&lt;</span><span class="token class-name">DegradeRule</span><span class="token punctuation">&gt;</span><span class="token punctuation">&gt;</span></span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token punctuation">}</span>
    <span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token keyword">private</span> <span class="token class-name">Converter</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">String</span><span class="token punctuation">,</span> <span class="token class-name">List</span><span class="token punctuation">&lt;</span><span class="token class-name">SystemRule</span><span class="token punctuation">&gt;</span><span class="token punctuation">&gt;</span></span> systemRuleListParser <span class="token operator">=</span> source <span class="token operator">-&gt;</span> JSON<span class="token punctuation">.</span><span class="token function">parseObject</span><span class="token punctuation">(</span>
            source<span class="token punctuation">,</span>
            <span class="token keyword">new</span> <span class="token class-name">TypeReference</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">List</span><span class="token punctuation">&lt;</span><span class="token class-name">SystemRule</span><span class="token punctuation">&gt;</span><span class="token punctuation">&gt;</span></span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token punctuation">}</span>
    <span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token keyword">private</span> <span class="token class-name">Converter</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">String</span><span class="token punctuation">,</span> <span class="token class-name">List</span><span class="token punctuation">&lt;</span><span class="token class-name">AuthorityRule</span><span class="token punctuation">&gt;</span><span class="token punctuation">&gt;</span></span> authorityRuleListParser <span class="token operator">=</span> source <span class="token operator">-&gt;</span> JSON<span class="token punctuation">.</span><span class="token function">parseObject</span><span class="token punctuation">(</span>
            source<span class="token punctuation">,</span>
            <span class="token keyword">new</span> <span class="token class-name">TypeReference</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">List</span><span class="token punctuation">&lt;</span><span class="token class-name">AuthorityRule</span><span class="token punctuation">&gt;</span><span class="token punctuation">&gt;</span></span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token punctuation">}</span>
    <span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token keyword">private</span> <span class="token class-name">Converter</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">String</span><span class="token punctuation">,</span> <span class="token class-name">List</span><span class="token punctuation">&lt;</span><span class="token class-name">ParamFlowRule</span><span class="token punctuation">&gt;</span><span class="token punctuation">&gt;</span></span> paramFlowRuleListParser <span class="token operator">=</span> source <span class="token operator">-&gt;</span> JSON<span class="token punctuation">.</span><span class="token function">parseObject</span><span class="token punctuation">(</span>
            source<span class="token punctuation">,</span>
            <span class="token keyword">new</span> <span class="token class-name">TypeReference</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">List</span><span class="token punctuation">&lt;</span><span class="token class-name">ParamFlowRule</span><span class="token punctuation">&gt;</span><span class="token punctuation">&gt;</span></span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token punctuation">}</span>
    <span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token keyword">private</span> <span class="token keyword">void</span> <span class="token function">mkdirIfNotExits</span><span class="token punctuation">(</span><span class="token class-name">String</span> filePath<span class="token punctuation">)</span> <span class="token keyword">throws</span> <span class="token class-name">IOException</span> <span class="token punctuation">{</span>
        <span class="token class-name">File</span> file <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">File</span><span class="token punctuation">(</span>filePath<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token operator">!</span>file<span class="token punctuation">.</span><span class="token function">exists</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            file<span class="token punctuation">.</span><span class="token function">mkdirs</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">private</span> <span class="token keyword">void</span> <span class="token function">createFileIfNotExits</span><span class="token punctuation">(</span><span class="token class-name">String</span> filePath<span class="token punctuation">)</span> <span class="token keyword">throws</span> <span class="token class-name">IOException</span> <span class="token punctuation">{</span>
        <span class="token class-name">File</span> file <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">File</span><span class="token punctuation">(</span>filePath<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token operator">!</span>file<span class="token punctuation">.</span><span class="token function">exists</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            file<span class="token punctuation">.</span><span class="token function">createNewFile</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">private</span> <span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">T</span><span class="token punctuation">&gt;</span></span> <span class="token class-name">String</span> <span class="token function">encodeJson</span><span class="token punctuation">(</span><span class="token class-name">T</span> t<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">return</span> JSON<span class="token punctuation">.</span><span class="token function">toJSONString</span><span class="token punctuation">(</span>t<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br><span class="line-number">32</span><br><span class="line-number">33</span><br><span class="line-number">34</span><br><span class="line-number">35</span><br><span class="line-number">36</span><br><span class="line-number">37</span><br><span class="line-number">38</span><br><span class="line-number">39</span><br><span class="line-number">40</span><br><span class="line-number">41</span><br><span class="line-number">42</span><br><span class="line-number">43</span><br><span class="line-number">44</span><br><span class="line-number">45</span><br><span class="line-number">46</span><br><span class="line-number">47</span><br><span class="line-number">48</span><br><span class="line-number">49</span><br><span class="line-number">50</span><br><span class="line-number">51</span><br><span class="line-number">52</span><br><span class="line-number">53</span><br><span class="line-number">54</span><br><span class="line-number">55</span><br><span class="line-number">56</span><br><span class="line-number">57</span><br><span class="line-number">58</span><br><span class="line-number">59</span><br><span class="line-number">60</span><br><span class="line-number">61</span><br><span class="line-number">62</span><br><span class="line-number">63</span><br><span class="line-number">64</span><br><span class="line-number">65</span><br><span class="line-number">66</span><br><span class="line-number">67</span><br><span class="line-number">68</span><br><span class="line-number">69</span><br><span class="line-number">70</span><br><span class="line-number">71</span><br><span class="line-number">72</span><br><span class="line-number">73</span><br><span class="line-number">74</span><br><span class="line-number">75</span><br><span class="line-number">76</span><br><span class="line-number">77</span><br><span class="line-number">78</span><br><span class="line-number">79</span><br><span class="line-number">80</span><br><span class="line-number">81</span><br><span class="line-number">82</span><br><span class="line-number">83</span><br><span class="line-number">84</span><br><span class="line-number">85</span><br><span class="line-number">86</span><br><span class="line-number">87</span><br><span class="line-number">88</span><br><span class="line-number">89</span><br><span class="line-number">90</span><br><span class="line-number">91</span><br><span class="line-number">92</span><br><span class="line-number">93</span><br><span class="line-number">94</span><br><span class="line-number">95</span><br><span class="line-number">96</span><br><span class="line-number">97</span><br><span class="line-number">98</span><br><span class="line-number">99</span><br><span class="line-number">100</span><br><span class="line-number">101</span><br><span class="line-number">102</span><br><span class="line-number">103</span><br><span class="line-number">104</span><br><span class="line-number">105</span><br><span class="line-number">106</span><br><span class="line-number">107</span><br><span class="line-number">108</span><br><span class="line-number">109</span><br><span class="line-number">110</span><br><span class="line-number">111</span><br><span class="line-number">112</span><br><span class="line-number">113</span><br><span class="line-number">114</span><br><span class="line-number">115</span><br><span class="line-number">116</span><br><span class="line-number">117</span><br><span class="line-number">118</span><br><span class="line-number">119</span><br><span class="line-number">120</span><br><span class="line-number">121</span><br><span class="line-number">122</span><br><span class="line-number">123</span><br><span class="line-number">124</span><br><span class="line-number">125</span><br><span class="line-number">126</span><br><span class="line-number">127</span><br><span class="line-number">128</span><br><span class="line-number">129</span><br><span class="line-number">130</span><br><span class="line-number">131</span><br></div></div><p>（2）在订单微服务的resources目录下新建META-INF目录，并在META-INF目录下新建services目录，在services目录下新建名称为<code>com.alibaba.csp.sentinel.init.InitFunc</code>的文件，如下所示。</p> <p><img alt="sa-2022-05-05-049" data-src="https://binghe001.github.io/assets/images/microservices/springcloudalibaba/sa-2022-05-05-049.png" loading="lazy" class="lazy"></p> <p>（3）在<code>com.alibaba.csp.sentinel.init.InitFunc</code>文件中添加<code>io.binghe.shop.order.persistence.SentinelPersistenceRule</code>类的全类名，如下所示。</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token class-name"><span class="token namespace">io<span class="token punctuation">.</span>binghe<span class="token punctuation">.</span>shop<span class="token punctuation">.</span>order<span class="token punctuation">.</span>persistence<span class="token punctuation">.</span></span>SentinelPersistenceRule</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p><img alt="sa-2022-05-05-050" data-src="https://binghe001.github.io/assets/images/microservices/springcloudalibaba/sa-2022-05-05-050.png" loading="lazy" class="lazy"></p> <p>（4）首先在浏览器中访问<code>http://localhost:8080/order/request_sentinel6</code>，在Sentinel的簇点链路里找到/request_sentinel6。</p> <p><img alt="sa-2022-05-05-045" data-src="https://binghe001.github.io/assets/images/microservices/springcloudalibaba/sa-2022-05-05-045.png" loading="lazy" class="lazy"></p> <p>（5）点击流控按钮进入流控规则页面，按照下图方式进行配置。</p> <p><img alt="sa-2022-05-05-046" data-src="https://binghe001.github.io/assets/images/microservices/springcloudalibaba/sa-2022-05-05-046.png" loading="lazy" class="lazy"></p> <p>（6）点击新增按钮，此时打开电脑的<code>user.home</code>目录，我电脑的目录为<code>C:\Users\binghe</code>，可以发现<code>C:\Users\binghe</code>目录中多了一个sentinel-rules目录。</p> <p><img alt="sa-2022-05-05-051" data-src="https://binghe001.github.io/assets/images/microservices/springcloudalibaba/sa-2022-05-05-051.png" loading="lazy" class="lazy"></p> <p>（7）打开sentinel-rules目录，发现里面存在一个server-order目录，如下所示。</p> <p><img alt="sa-2022-05-05-052" data-src="https://binghe001.github.io/assets/images/microservices/springcloudalibaba/sa-2022-05-05-052.png" loading="lazy" class="lazy"></p> <p>（8）打开server-order目录后，会发现生成了Sentinel的配置文件，并持久化到了磁盘上，如下所示。</p> <p><img alt="sa-2022-05-05-053" data-src="https://binghe001.github.io/assets/images/microservices/springcloudalibaba/sa-2022-05-05-053.png" loading="lazy" class="lazy"></p> <p>（9）打开flow-rule.json文件，内容如下所示。</p> <div class="language-json line-numbers-mode"><pre class="language-json"><code><span class="token punctuation">[</span>
    <span class="token punctuation">{</span>
        <span class="token property">&quot;clusterConfig&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
            <span class="token property">&quot;acquireRefuseStrategy&quot;</span><span class="token operator">:</span> <span class="token number">0</span><span class="token punctuation">,</span>
            <span class="token property">&quot;clientOfflineTime&quot;</span><span class="token operator">:</span> <span class="token number">2000</span><span class="token punctuation">,</span>
            <span class="token property">&quot;fallbackToLocalWhenFail&quot;</span><span class="token operator">:</span> <span class="token boolean">true</span><span class="token punctuation">,</span>
            <span class="token property">&quot;resourceTimeout&quot;</span><span class="token operator">:</span> <span class="token number">2000</span><span class="token punctuation">,</span>
            <span class="token property">&quot;resourceTimeoutStrategy&quot;</span><span class="token operator">:</span> <span class="token number">0</span><span class="token punctuation">,</span>
            <span class="token property">&quot;sampleCount&quot;</span><span class="token operator">:</span> <span class="token number">10</span><span class="token punctuation">,</span>
            <span class="token property">&quot;strategy&quot;</span><span class="token operator">:</span> <span class="token number">0</span><span class="token punctuation">,</span>
            <span class="token property">&quot;thresholdType&quot;</span><span class="token operator">:</span> <span class="token number">0</span><span class="token punctuation">,</span>
            <span class="token property">&quot;windowIntervalMs&quot;</span><span class="token operator">:</span> <span class="token number">1000</span>
        <span class="token punctuation">}</span><span class="token punctuation">,</span>
        <span class="token property">&quot;clusterMode&quot;</span><span class="token operator">:</span> <span class="token boolean">false</span><span class="token punctuation">,</span>
        <span class="token property">&quot;controlBehavior&quot;</span><span class="token operator">:</span> <span class="token number">0</span><span class="token punctuation">,</span>
        <span class="token property">&quot;count&quot;</span><span class="token operator">:</span> <span class="token number">2</span><span class="token punctuation">,</span>
        <span class="token property">&quot;grade&quot;</span><span class="token operator">:</span> <span class="token number">1</span><span class="token punctuation">,</span>
        <span class="token property">&quot;limitApp&quot;</span><span class="token operator">:</span> <span class="token string">&quot;default&quot;</span><span class="token punctuation">,</span>
        <span class="token property">&quot;maxQueueingTimeMs&quot;</span><span class="token operator">:</span> <span class="token number">500</span><span class="token punctuation">,</span>
        <span class="token property">&quot;resource&quot;</span><span class="token operator">:</span> <span class="token string">&quot;/request_sentinel6&quot;</span><span class="token punctuation">,</span>
        <span class="token property">&quot;strategy&quot;</span><span class="token operator">:</span> <span class="token number">0</span><span class="token punctuation">,</span>
        <span class="token property">&quot;warmUpPeriodSec&quot;</span><span class="token operator">:</span> <span class="token number">10</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">]</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br></div></div><p>可以看到，flow-rule.json文件中持久化了对于<code>/request_sentinel6</code>接口的配置。</p> <p>至此，我们完成了Sentinel规则的持久化。</p> <h2 id="关于星球"><a href="#关于星球" class="header-anchor">#</a> 关于星球</h2> <p>《<a href="https://mp.weixin.qq.com/mp/appmsgalbum?__biz=Mzg4MjU0OTM1OA==&amp;action=getalbum&amp;album_id=2337104419664084992&amp;scene=173&amp;from_msgid=2247500214&amp;from_itemidx=1&amp;count=3&amp;nolastread=1#wechat_redirect" target="_blank" rel="noopener noreferrer">SpringCloud Alibaba实战<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a>》专栏一不小心就更新了11章了，如何更好的跟上冰河的节奏，一起搞定《<a href="https://mp.weixin.qq.com/mp/appmsgalbum?__biz=Mzg4MjU0OTM1OA==&amp;action=getalbum&amp;album_id=2337104419664084992&amp;scene=173&amp;from_msgid=2247500214&amp;from_itemidx=1&amp;count=3&amp;nolastread=1#wechat_redirect" target="_blank" rel="noopener noreferrer">SpringCloud Alibaba实战<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a>》呢？</p> <p>最近，冰河创建了【冰河技术】知识星球，《<a href="https://mp.weixin.qq.com/mp/appmsgalbum?__biz=Mzg4MjU0OTM1OA==&amp;action=getalbum&amp;album_id=2337104419664084992&amp;scene=173&amp;from_msgid=2247500214&amp;from_itemidx=1&amp;count=3&amp;nolastread=1#wechat_redirect" target="_blank" rel="noopener noreferrer">SpringCloud Alibaba实战<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a>》专栏的源码获取方式会放到知识星球中，同时在微信上会创建专门的知识星球群，冰河会在知识星球上和星球群里解答球友的提问。</p> <h3 id="星球提供的服务"><a href="#星球提供的服务" class="header-anchor">#</a> 星球提供的服务</h3> <p>冰河整理了星球提供的一些服务，如下所示。</p> <p>加入星球，你将获得：</p> <p>1.学习SpringCloud Alibaba实战项目—从零开发微服务项目</p> <p>2.学习高并发、大流量业务场景的解决方案，体验大厂真正的高并发、大流量的业务场景</p> <p>3.学习进大厂必备技能：性能调优、并发编程、分布式、微服务、框架源码、中间件开发、项目实战</p> <p>4.提供站点 https://binghe001.github.io 所有学习内容的指导、帮助</p> <p>5.GitHub：https://github.com/binghe001/BingheGuide - 非常有价值的技术资料仓库，包括冰河所有的博客开放案例代码</p> <p>6.可以发送你的简历到我的邮箱，提供简历批阅服务</p> <p>7.提供技术问题、系统架构、学习成长、晋升答辩等各项内容的回答</p> <p>8.定期的整理和分享出各类专属星球的技术小册、电子书、编程视频、PDF文件</p> <p>9.定期组织技术直播分享，传道、授业、解惑，指导阶段瓶颈突破技巧</p> <h3 id="星球门票价格"><a href="#星球门票价格" class="header-anchor">#</a> 星球门票价格</h3> <p>星球目前的门票价格50元，随着每次加入新实战项目和分享硬核技术上调入场价格。</p> <p>最后，小伙伴们可以扫描或者长按下图中的二维码加入星球，也可以在 <strong>冰河技术</strong> 公众号回复“ <strong>星球</strong> ”，领取入场优惠券。</p> <p><img alt="sa-2022-04-21-007" data-src="https://binghe001.github.io/assets/images/microservices/springcloudalibaba/sa-2022-04-28-008.png" loading="lazy" class="lazy"></p> <p><strong>好了，今天就到这儿吧，我是冰河，我们下期见~~</strong></p> <h2 id="写在最后"><a href="#写在最后" class="header-anchor">#</a> 写在最后</h2> <blockquote><p>如果你觉得冰河写的还不错，请微信搜索并关注「 <strong>冰河技术</strong> 」微信公众号，跟冰河学习高并发、分布式、微服务、大数据、互联网和云原生技术，「 <strong>冰河技术</strong> 」微信公众号更新了大量技术专题，每一篇技术文章干货满满！不少读者已经通过阅读「 <strong>冰河技术</strong> 」微信公众号文章，吊打面试官，成功跳槽到大厂；也有不少读者实现了技术上的飞跃，成为公司的技术骨干！如果你也想像他们一样提升自己的能力，实现技术能力的飞跃，进大厂，升职加薪，那就关注「 <strong>冰河技术</strong> 」微信公众号吧，每天更新超硬核技术干货，让你对如何提升技术能力不再迷茫！</p></blockquote> <p><img alt="" data-src="https://img-blog.csdnimg.cn/20200906013715889.png" loading="lazy" class="lazy"></p></div> <footer class="page-edit"><div class="edit-link"><a href="https://github.com/binghe001/BingheGuide/edit/master/docs/md/microservices/springcloudalibaba/2022-05-05-SA实战-第11章-服务容错加餐-Sentinel核心技术与配置规则.md" target="_blank" rel="noopener noreferrer">在 GitHub 上编辑此页</a> <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></div> <div class="last-updated"><span class="prefix">上次更新: </span> <span class="time">2022/5/23</span></div></footer> <div class="page-nav"><p class="inner"><span class="prev">
        ←
        <a href="/md/microservices/springcloudalibaba/2022-05-03-SA实战-第10章-服务容错-Fegin整合Sentinel.html" class="prev">
          SA实战 ·《SpringCloud Alibaba实战》第10章-服务容错：项目整合Sentinel实现限流与容错
        </a></span> <span class="next"><a href="/md/microservices/springcloudalibaba/2022-05-08-SA实战-第12章-服务网关-网关概述与核心架构.html">
          SA实战 ·《SpringCloud Alibaba实战》第12章-服务网关：网关概述与核心架构
        </a>
        →
      </span></p></div> </main></div> <aside class="page-sidebar"> <div class="page-side-toolbar"><div class="option-box-toc-fixed"><div class="toc-container-sidebar"><div class="pos-box"><div class="icon-arrow"></div> <div class="scroll-box" style="max-height:650px"><div style="font-weight:bold;text-align:center;">SA实战 ·《SpringCloud Alibaba实战》第11章-服务容错加餐：Sentinel核心技术与配置规则（最全使用教程）</div> <hr> <div class="toc-box"><ul class="toc-sidebar-links"><li><a href="/md/microservices/springcloudalibaba/2022-05-05-SA%E5%AE%9E%E6%88%98-%E7%AC%AC11%E7%AB%A0-%E6%9C%8D%E5%8A%A1%E5%AE%B9%E9%94%99%E5%8A%A0%E9%A4%90-Sentinel%E6%A0%B8%E5%BF%83%E6%8A%80%E6%9C%AF%E4%B8%8E%E9%85%8D%E7%BD%AE%E8%A7%84%E5%88%99.html#本章总览" class="toc-sidebar-link">本章总览</a><ul class="toc-sidebar-sub-headers"></ul></li><li><a href="/md/microservices/springcloudalibaba/2022-05-05-SA%E5%AE%9E%E6%88%98-%E7%AC%AC11%E7%AB%A0-%E6%9C%8D%E5%8A%A1%E5%AE%B9%E9%94%99%E5%8A%A0%E9%A4%90-Sentinel%E6%A0%B8%E5%BF%83%E6%8A%80%E6%9C%AF%E4%B8%8E%E9%85%8D%E7%BD%AE%E8%A7%84%E5%88%99.html#sentinel核心功能" class="toc-sidebar-link">Sentinel核心功能</a><ul class="toc-sidebar-sub-headers"><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-05-05-SA%E5%AE%9E%E6%88%98-%E7%AC%AC11%E7%AB%A0-%E6%9C%8D%E5%8A%A1%E5%AE%B9%E9%94%99%E5%8A%A0%E9%A4%90-Sentinel%E6%A0%B8%E5%BF%83%E6%8A%80%E6%9C%AF%E4%B8%8E%E9%85%8D%E7%BD%AE%E8%A7%84%E5%88%99.html#流量控制" class="toc-sidebar-link">流量控制</a></li><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-05-05-SA%E5%AE%9E%E6%88%98-%E7%AC%AC11%E7%AB%A0-%E6%9C%8D%E5%8A%A1%E5%AE%B9%E9%94%99%E5%8A%A0%E9%A4%90-Sentinel%E6%A0%B8%E5%BF%83%E6%8A%80%E6%9C%AF%E4%B8%8E%E9%85%8D%E7%BD%AE%E8%A7%84%E5%88%99.html#熔断降级" class="toc-sidebar-link">熔断降级</a></li><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-05-05-SA%E5%AE%9E%E6%88%98-%E7%AC%AC11%E7%AB%A0-%E6%9C%8D%E5%8A%A1%E5%AE%B9%E9%94%99%E5%8A%A0%E9%A4%90-Sentinel%E6%A0%B8%E5%BF%83%E6%8A%80%E6%9C%AF%E4%B8%8E%E9%85%8D%E7%BD%AE%E8%A7%84%E5%88%99.html#系统负载保护" class="toc-sidebar-link">系统负载保护</a></li></ul></li><li><a href="/md/microservices/springcloudalibaba/2022-05-05-SA%E5%AE%9E%E6%88%98-%E7%AC%AC11%E7%AB%A0-%E6%9C%8D%E5%8A%A1%E5%AE%B9%E9%94%99%E5%8A%A0%E9%A4%90-Sentinel%E6%A0%B8%E5%BF%83%E6%8A%80%E6%9C%AF%E4%B8%8E%E9%85%8D%E7%BD%AE%E8%A7%84%E5%88%99.html#sentinel核心规则" class="toc-sidebar-link">Sentinel核心规则</a><ul class="toc-sidebar-sub-headers"></ul></li><li><a href="/md/microservices/springcloudalibaba/2022-05-05-SA%E5%AE%9E%E6%88%98-%E7%AC%AC11%E7%AB%A0-%E6%9C%8D%E5%8A%A1%E5%AE%B9%E9%94%99%E5%8A%A0%E9%A4%90-Sentinel%E6%A0%B8%E5%BF%83%E6%8A%80%E6%9C%AF%E4%B8%8E%E9%85%8D%E7%BD%AE%E8%A7%84%E5%88%99.html#流控规则" class="toc-sidebar-link">流控规则</a><ul class="toc-sidebar-sub-headers"><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-05-05-SA%E5%AE%9E%E6%88%98-%E7%AC%AC11%E7%AB%A0-%E6%9C%8D%E5%8A%A1%E5%AE%B9%E9%94%99%E5%8A%A0%E9%A4%90-Sentinel%E6%A0%B8%E5%BF%83%E6%8A%80%E6%9C%AF%E4%B8%8E%E9%85%8D%E7%BD%AE%E8%A7%84%E5%88%99.html#簇点链路规则" class="toc-sidebar-link">簇点链路规则</a></li><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-05-05-SA%E5%AE%9E%E6%88%98-%E7%AC%AC11%E7%AB%A0-%E6%9C%8D%E5%8A%A1%E5%AE%B9%E9%94%99%E5%8A%A0%E9%A4%90-Sentinel%E6%A0%B8%E5%BF%83%E6%8A%80%E6%9C%AF%E4%B8%8E%E9%85%8D%E7%BD%AE%E8%A7%84%E5%88%99.html#配置简单限流" class="toc-sidebar-link">配置简单限流</a></li><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-05-05-SA%E5%AE%9E%E6%88%98-%E7%AC%AC11%E7%AB%A0-%E6%9C%8D%E5%8A%A1%E5%AE%B9%E9%94%99%E5%8A%A0%E9%A4%90-Sentinel%E6%A0%B8%E5%BF%83%E6%8A%80%E6%9C%AF%E4%B8%8E%E9%85%8D%E7%BD%AE%E8%A7%84%E5%88%99.html#配置流控模式" class="toc-sidebar-link">配置流控模式</a></li></ul></li><li><a href="/md/microservices/springcloudalibaba/2022-05-05-SA%E5%AE%9E%E6%88%98-%E7%AC%AC11%E7%AB%A0-%E6%9C%8D%E5%8A%A1%E5%AE%B9%E9%94%99%E5%8A%A0%E9%A4%90-Sentinel%E6%A0%B8%E5%BF%83%E6%8A%80%E6%9C%AF%E4%B8%8E%E9%85%8D%E7%BD%AE%E8%A7%84%E5%88%99.html#熔断规则" class="toc-sidebar-link">熔断规则</a><ul class="toc-sidebar-sub-headers"><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-05-05-SA%E5%AE%9E%E6%88%98-%E7%AC%AC11%E7%AB%A0-%E6%9C%8D%E5%8A%A1%E5%AE%B9%E9%94%99%E5%8A%A0%E9%A4%90-Sentinel%E6%A0%B8%E5%BF%83%E6%8A%80%E6%9C%AF%E4%B8%8E%E9%85%8D%E7%BD%AE%E8%A7%84%E5%88%99.html#熔断规则概述" class="toc-sidebar-link">熔断规则概述</a></li><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-05-05-SA%E5%AE%9E%E6%88%98-%E7%AC%AC11%E7%AB%A0-%E6%9C%8D%E5%8A%A1%E5%AE%B9%E9%94%99%E5%8A%A0%E9%A4%90-Sentinel%E6%A0%B8%E5%BF%83%E6%8A%80%E6%9C%AF%E4%B8%8E%E9%85%8D%E7%BD%AE%E8%A7%84%E5%88%99.html#演示基于慢调用比例熔断" class="toc-sidebar-link">演示基于慢调用比例熔断</a></li><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-05-05-SA%E5%AE%9E%E6%88%98-%E7%AC%AC11%E7%AB%A0-%E6%9C%8D%E5%8A%A1%E5%AE%B9%E9%94%99%E5%8A%A0%E9%A4%90-Sentinel%E6%A0%B8%E5%BF%83%E6%8A%80%E6%9C%AF%E4%B8%8E%E9%85%8D%E7%BD%AE%E8%A7%84%E5%88%99.html#演示基于异常比例熔断" class="toc-sidebar-link">演示基于异常比例熔断</a></li><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-05-05-SA%E5%AE%9E%E6%88%98-%E7%AC%AC11%E7%AB%A0-%E6%9C%8D%E5%8A%A1%E5%AE%B9%E9%94%99%E5%8A%A0%E9%A4%90-Sentinel%E6%A0%B8%E5%BF%83%E6%8A%80%E6%9C%AF%E4%B8%8E%E9%85%8D%E7%BD%AE%E8%A7%84%E5%88%99.html#演示基于异常数熔断" class="toc-sidebar-link">演示基于异常数熔断</a></li></ul></li><li><a href="/md/microservices/springcloudalibaba/2022-05-05-SA%E5%AE%9E%E6%88%98-%E7%AC%AC11%E7%AB%A0-%E6%9C%8D%E5%8A%A1%E5%AE%B9%E9%94%99%E5%8A%A0%E9%A4%90-Sentinel%E6%A0%B8%E5%BF%83%E6%8A%80%E6%9C%AF%E4%B8%8E%E9%85%8D%E7%BD%AE%E8%A7%84%E5%88%99.html#热点规则" class="toc-sidebar-link">热点规则</a><ul class="toc-sidebar-sub-headers"><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-05-05-SA%E5%AE%9E%E6%88%98-%E7%AC%AC11%E7%AB%A0-%E6%9C%8D%E5%8A%A1%E5%AE%B9%E9%94%99%E5%8A%A0%E9%A4%90-Sentinel%E6%A0%B8%E5%BF%83%E6%8A%80%E6%9C%AF%E4%B8%8E%E9%85%8D%E7%BD%AE%E8%A7%84%E5%88%99.html#热点规则概述" class="toc-sidebar-link">热点规则概述</a></li><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-05-05-SA%E5%AE%9E%E6%88%98-%E7%AC%AC11%E7%AB%A0-%E6%9C%8D%E5%8A%A1%E5%AE%B9%E9%94%99%E5%8A%A0%E9%A4%90-Sentinel%E6%A0%B8%E5%BF%83%E6%8A%80%E6%9C%AF%E4%B8%8E%E9%85%8D%E7%BD%AE%E8%A7%84%E5%88%99.html#演示热点规则" class="toc-sidebar-link">演示热点规则</a></li><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-05-05-SA%E5%AE%9E%E6%88%98-%E7%AC%AC11%E7%AB%A0-%E6%9C%8D%E5%8A%A1%E5%AE%B9%E9%94%99%E5%8A%A0%E9%A4%90-Sentinel%E6%A0%B8%E5%BF%83%E6%8A%80%E6%9C%AF%E4%B8%8E%E9%85%8D%E7%BD%AE%E8%A7%84%E5%88%99.html#演示热点高级选项规则" class="toc-sidebar-link">演示热点高级选项规则</a></li></ul></li><li><a href="/md/microservices/springcloudalibaba/2022-05-05-SA%E5%AE%9E%E6%88%98-%E7%AC%AC11%E7%AB%A0-%E6%9C%8D%E5%8A%A1%E5%AE%B9%E9%94%99%E5%8A%A0%E9%A4%90-Sentinel%E6%A0%B8%E5%BF%83%E6%8A%80%E6%9C%AF%E4%B8%8E%E9%85%8D%E7%BD%AE%E8%A7%84%E5%88%99.html#授权规则" class="toc-sidebar-link">授权规则</a><ul class="toc-sidebar-sub-headers"><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-05-05-SA%E5%AE%9E%E6%88%98-%E7%AC%AC11%E7%AB%A0-%E6%9C%8D%E5%8A%A1%E5%AE%B9%E9%94%99%E5%8A%A0%E9%A4%90-Sentinel%E6%A0%B8%E5%BF%83%E6%8A%80%E6%9C%AF%E4%B8%8E%E9%85%8D%E7%BD%AE%E8%A7%84%E5%88%99.html#授权规则概述" class="toc-sidebar-link">授权规则概述</a></li><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-05-05-SA%E5%AE%9E%E6%88%98-%E7%AC%AC11%E7%AB%A0-%E6%9C%8D%E5%8A%A1%E5%AE%B9%E9%94%99%E5%8A%A0%E9%A4%90-Sentinel%E6%A0%B8%E5%BF%83%E6%8A%80%E6%9C%AF%E4%B8%8E%E9%85%8D%E7%BD%AE%E8%A7%84%E5%88%99.html#演示授权规则" class="toc-sidebar-link">演示授权规则</a></li></ul></li><li><a href="/md/microservices/springcloudalibaba/2022-05-05-SA%E5%AE%9E%E6%88%98-%E7%AC%AC11%E7%AB%A0-%E6%9C%8D%E5%8A%A1%E5%AE%B9%E9%94%99%E5%8A%A0%E9%A4%90-Sentinel%E6%A0%B8%E5%BF%83%E6%8A%80%E6%9C%AF%E4%B8%8E%E9%85%8D%E7%BD%AE%E8%A7%84%E5%88%99.html#系统规则" class="toc-sidebar-link">系统规则</a><ul class="toc-sidebar-sub-headers"><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-05-05-SA%E5%AE%9E%E6%88%98-%E7%AC%AC11%E7%AB%A0-%E6%9C%8D%E5%8A%A1%E5%AE%B9%E9%94%99%E5%8A%A0%E9%A4%90-Sentinel%E6%A0%B8%E5%BF%83%E6%8A%80%E6%9C%AF%E4%B8%8E%E9%85%8D%E7%BD%AE%E8%A7%84%E5%88%99.html#系统规则概述" class="toc-sidebar-link">系统规则概述</a></li><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-05-05-SA%E5%AE%9E%E6%88%98-%E7%AC%AC11%E7%AB%A0-%E6%9C%8D%E5%8A%A1%E5%AE%B9%E9%94%99%E5%8A%A0%E9%A4%90-Sentinel%E6%A0%B8%E5%BF%83%E6%8A%80%E6%9C%AF%E4%B8%8E%E9%85%8D%E7%BD%AE%E8%A7%84%E5%88%99.html#演示系统规则" class="toc-sidebar-link">演示系统规则</a></li></ul></li><li><a href="/md/microservices/springcloudalibaba/2022-05-05-SA%E5%AE%9E%E6%88%98-%E7%AC%AC11%E7%AB%A0-%E6%9C%8D%E5%8A%A1%E5%AE%B9%E9%94%99%E5%8A%A0%E9%A4%90-Sentinel%E6%A0%B8%E5%BF%83%E6%8A%80%E6%9C%AF%E4%B8%8E%E9%85%8D%E7%BD%AE%E8%A7%84%E5%88%99.html#sentinelresource注解" class="toc-sidebar-link">@SentinelResource注解</a><ul class="toc-sidebar-sub-headers"><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-05-05-SA%E5%AE%9E%E6%88%98-%E7%AC%AC11%E7%AB%A0-%E6%9C%8D%E5%8A%A1%E5%AE%B9%E9%94%99%E5%8A%A0%E9%A4%90-Sentinel%E6%A0%B8%E5%BF%83%E6%8A%80%E6%9C%AF%E4%B8%8E%E9%85%8D%E7%BD%AE%E8%A7%84%E5%88%99.html#sentinelresource注解概述" class="toc-sidebar-link">@SentinelResource注解概述</a></li><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-05-05-SA%E5%AE%9E%E6%88%98-%E7%AC%AC11%E7%AB%A0-%E6%9C%8D%E5%8A%A1%E5%AE%B9%E9%94%99%E5%8A%A0%E9%A4%90-Sentinel%E6%A0%B8%E5%BF%83%E6%8A%80%E6%9C%AF%E4%B8%8E%E9%85%8D%E7%BD%AE%E8%A7%84%E5%88%99.html#演示-sentinelresource注解" class="toc-sidebar-link">演示@SentinelResource注解</a></li></ul></li><li><a href="/md/microservices/springcloudalibaba/2022-05-05-SA%E5%AE%9E%E6%88%98-%E7%AC%AC11%E7%AB%A0-%E6%9C%8D%E5%8A%A1%E5%AE%B9%E9%94%99%E5%8A%A0%E9%A4%90-Sentinel%E6%A0%B8%E5%BF%83%E6%8A%80%E6%9C%AF%E4%B8%8E%E9%85%8D%E7%BD%AE%E8%A7%84%E5%88%99.html#sentinel持久化" class="toc-sidebar-link">Sentinel持久化</a><ul class="toc-sidebar-sub-headers"><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-05-05-SA%E5%AE%9E%E6%88%98-%E7%AC%AC11%E7%AB%A0-%E6%9C%8D%E5%8A%A1%E5%AE%B9%E9%94%99%E5%8A%A0%E9%A4%90-Sentinel%E6%A0%B8%E5%BF%83%E6%8A%80%E6%9C%AF%E4%B8%8E%E9%85%8D%E7%BD%AE%E8%A7%84%E5%88%99.html#sentinel持久化概述" class="toc-sidebar-link">Sentinel持久化概述</a></li><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-05-05-SA%E5%AE%9E%E6%88%98-%E7%AC%AC11%E7%AB%A0-%E6%9C%8D%E5%8A%A1%E5%AE%B9%E9%94%99%E5%8A%A0%E9%A4%90-Sentinel%E6%A0%B8%E5%BF%83%E6%8A%80%E6%9C%AF%E4%B8%8E%E9%85%8D%E7%BD%AE%E8%A7%84%E5%88%99.html#实现sentinel的持久化" class="toc-sidebar-link">实现Sentinel的持久化</a></li></ul></li><li><a href="/md/microservices/springcloudalibaba/2022-05-05-SA%E5%AE%9E%E6%88%98-%E7%AC%AC11%E7%AB%A0-%E6%9C%8D%E5%8A%A1%E5%AE%B9%E9%94%99%E5%8A%A0%E9%A4%90-Sentinel%E6%A0%B8%E5%BF%83%E6%8A%80%E6%9C%AF%E4%B8%8E%E9%85%8D%E7%BD%AE%E8%A7%84%E5%88%99.html#关于星球" class="toc-sidebar-link">关于星球</a><ul class="toc-sidebar-sub-headers"><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-05-05-SA%E5%AE%9E%E6%88%98-%E7%AC%AC11%E7%AB%A0-%E6%9C%8D%E5%8A%A1%E5%AE%B9%E9%94%99%E5%8A%A0%E9%A4%90-Sentinel%E6%A0%B8%E5%BF%83%E6%8A%80%E6%9C%AF%E4%B8%8E%E9%85%8D%E7%BD%AE%E8%A7%84%E5%88%99.html#星球提供的服务" class="toc-sidebar-link">星球提供的服务</a></li><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-05-05-SA%E5%AE%9E%E6%88%98-%E7%AC%AC11%E7%AB%A0-%E6%9C%8D%E5%8A%A1%E5%AE%B9%E9%94%99%E5%8A%A0%E9%A4%90-Sentinel%E6%A0%B8%E5%BF%83%E6%8A%80%E6%9C%AF%E4%B8%8E%E9%85%8D%E7%BD%AE%E8%A7%84%E5%88%99.html#星球门票价格" class="toc-sidebar-link">星球门票价格</a></li></ul></li><li><a href="/md/microservices/springcloudalibaba/2022-05-05-SA%E5%AE%9E%E6%88%98-%E7%AC%AC11%E7%AB%A0-%E6%9C%8D%E5%8A%A1%E5%AE%B9%E9%94%99%E5%8A%A0%E9%A4%90-Sentinel%E6%A0%B8%E5%BF%83%E6%8A%80%E6%9C%AF%E4%B8%8E%E9%85%8D%E7%BD%AE%E8%A7%84%E5%88%99.html#写在最后" class="toc-sidebar-link">写在最后</a><ul class="toc-sidebar-sub-headers"></ul></li></ul></div></div></div></div></div> <div class="option-box-toc-over"><img src="/images/system/toc.png" class="nozoom"> <span class="show-txt">目录</span> <div class="toc-container"><div class="pos-box"><div class="icon-arrow"></div> <div class="scroll-box" style="max-height:550px"><div style="font-weight:bold;text-align:center;">SA实战 ·《SpringCloud Alibaba实战》第11章-服务容错加餐：Sentinel核心技术与配置规则（最全使用教程）</div> <hr> <div class="toc-box"><ul class="toc-sidebar-links"><li><a href="/md/microservices/springcloudalibaba/2022-05-05-SA%E5%AE%9E%E6%88%98-%E7%AC%AC11%E7%AB%A0-%E6%9C%8D%E5%8A%A1%E5%AE%B9%E9%94%99%E5%8A%A0%E9%A4%90-Sentinel%E6%A0%B8%E5%BF%83%E6%8A%80%E6%9C%AF%E4%B8%8E%E9%85%8D%E7%BD%AE%E8%A7%84%E5%88%99.html#本章总览" class="toc-sidebar-link">本章总览</a><ul class="toc-sidebar-sub-headers"></ul></li><li><a href="/md/microservices/springcloudalibaba/2022-05-05-SA%E5%AE%9E%E6%88%98-%E7%AC%AC11%E7%AB%A0-%E6%9C%8D%E5%8A%A1%E5%AE%B9%E9%94%99%E5%8A%A0%E9%A4%90-Sentinel%E6%A0%B8%E5%BF%83%E6%8A%80%E6%9C%AF%E4%B8%8E%E9%85%8D%E7%BD%AE%E8%A7%84%E5%88%99.html#sentinel核心功能" class="toc-sidebar-link">Sentinel核心功能</a><ul class="toc-sidebar-sub-headers"><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-05-05-SA%E5%AE%9E%E6%88%98-%E7%AC%AC11%E7%AB%A0-%E6%9C%8D%E5%8A%A1%E5%AE%B9%E9%94%99%E5%8A%A0%E9%A4%90-Sentinel%E6%A0%B8%E5%BF%83%E6%8A%80%E6%9C%AF%E4%B8%8E%E9%85%8D%E7%BD%AE%E8%A7%84%E5%88%99.html#流量控制" class="toc-sidebar-link">流量控制</a></li><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-05-05-SA%E5%AE%9E%E6%88%98-%E7%AC%AC11%E7%AB%A0-%E6%9C%8D%E5%8A%A1%E5%AE%B9%E9%94%99%E5%8A%A0%E9%A4%90-Sentinel%E6%A0%B8%E5%BF%83%E6%8A%80%E6%9C%AF%E4%B8%8E%E9%85%8D%E7%BD%AE%E8%A7%84%E5%88%99.html#熔断降级" class="toc-sidebar-link">熔断降级</a></li><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-05-05-SA%E5%AE%9E%E6%88%98-%E7%AC%AC11%E7%AB%A0-%E6%9C%8D%E5%8A%A1%E5%AE%B9%E9%94%99%E5%8A%A0%E9%A4%90-Sentinel%E6%A0%B8%E5%BF%83%E6%8A%80%E6%9C%AF%E4%B8%8E%E9%85%8D%E7%BD%AE%E8%A7%84%E5%88%99.html#系统负载保护" class="toc-sidebar-link">系统负载保护</a></li></ul></li><li><a href="/md/microservices/springcloudalibaba/2022-05-05-SA%E5%AE%9E%E6%88%98-%E7%AC%AC11%E7%AB%A0-%E6%9C%8D%E5%8A%A1%E5%AE%B9%E9%94%99%E5%8A%A0%E9%A4%90-Sentinel%E6%A0%B8%E5%BF%83%E6%8A%80%E6%9C%AF%E4%B8%8E%E9%85%8D%E7%BD%AE%E8%A7%84%E5%88%99.html#sentinel核心规则" class="toc-sidebar-link">Sentinel核心规则</a><ul class="toc-sidebar-sub-headers"></ul></li><li><a href="/md/microservices/springcloudalibaba/2022-05-05-SA%E5%AE%9E%E6%88%98-%E7%AC%AC11%E7%AB%A0-%E6%9C%8D%E5%8A%A1%E5%AE%B9%E9%94%99%E5%8A%A0%E9%A4%90-Sentinel%E6%A0%B8%E5%BF%83%E6%8A%80%E6%9C%AF%E4%B8%8E%E9%85%8D%E7%BD%AE%E8%A7%84%E5%88%99.html#流控规则" class="toc-sidebar-link">流控规则</a><ul class="toc-sidebar-sub-headers"><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-05-05-SA%E5%AE%9E%E6%88%98-%E7%AC%AC11%E7%AB%A0-%E6%9C%8D%E5%8A%A1%E5%AE%B9%E9%94%99%E5%8A%A0%E9%A4%90-Sentinel%E6%A0%B8%E5%BF%83%E6%8A%80%E6%9C%AF%E4%B8%8E%E9%85%8D%E7%BD%AE%E8%A7%84%E5%88%99.html#簇点链路规则" class="toc-sidebar-link">簇点链路规则</a></li><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-05-05-SA%E5%AE%9E%E6%88%98-%E7%AC%AC11%E7%AB%A0-%E6%9C%8D%E5%8A%A1%E5%AE%B9%E9%94%99%E5%8A%A0%E9%A4%90-Sentinel%E6%A0%B8%E5%BF%83%E6%8A%80%E6%9C%AF%E4%B8%8E%E9%85%8D%E7%BD%AE%E8%A7%84%E5%88%99.html#配置简单限流" class="toc-sidebar-link">配置简单限流</a></li><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-05-05-SA%E5%AE%9E%E6%88%98-%E7%AC%AC11%E7%AB%A0-%E6%9C%8D%E5%8A%A1%E5%AE%B9%E9%94%99%E5%8A%A0%E9%A4%90-Sentinel%E6%A0%B8%E5%BF%83%E6%8A%80%E6%9C%AF%E4%B8%8E%E9%85%8D%E7%BD%AE%E8%A7%84%E5%88%99.html#配置流控模式" class="toc-sidebar-link">配置流控模式</a></li></ul></li><li><a href="/md/microservices/springcloudalibaba/2022-05-05-SA%E5%AE%9E%E6%88%98-%E7%AC%AC11%E7%AB%A0-%E6%9C%8D%E5%8A%A1%E5%AE%B9%E9%94%99%E5%8A%A0%E9%A4%90-Sentinel%E6%A0%B8%E5%BF%83%E6%8A%80%E6%9C%AF%E4%B8%8E%E9%85%8D%E7%BD%AE%E8%A7%84%E5%88%99.html#熔断规则" class="toc-sidebar-link">熔断规则</a><ul class="toc-sidebar-sub-headers"><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-05-05-SA%E5%AE%9E%E6%88%98-%E7%AC%AC11%E7%AB%A0-%E6%9C%8D%E5%8A%A1%E5%AE%B9%E9%94%99%E5%8A%A0%E9%A4%90-Sentinel%E6%A0%B8%E5%BF%83%E6%8A%80%E6%9C%AF%E4%B8%8E%E9%85%8D%E7%BD%AE%E8%A7%84%E5%88%99.html#熔断规则概述" class="toc-sidebar-link">熔断规则概述</a></li><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-05-05-SA%E5%AE%9E%E6%88%98-%E7%AC%AC11%E7%AB%A0-%E6%9C%8D%E5%8A%A1%E5%AE%B9%E9%94%99%E5%8A%A0%E9%A4%90-Sentinel%E6%A0%B8%E5%BF%83%E6%8A%80%E6%9C%AF%E4%B8%8E%E9%85%8D%E7%BD%AE%E8%A7%84%E5%88%99.html#演示基于慢调用比例熔断" class="toc-sidebar-link">演示基于慢调用比例熔断</a></li><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-05-05-SA%E5%AE%9E%E6%88%98-%E7%AC%AC11%E7%AB%A0-%E6%9C%8D%E5%8A%A1%E5%AE%B9%E9%94%99%E5%8A%A0%E9%A4%90-Sentinel%E6%A0%B8%E5%BF%83%E6%8A%80%E6%9C%AF%E4%B8%8E%E9%85%8D%E7%BD%AE%E8%A7%84%E5%88%99.html#演示基于异常比例熔断" class="toc-sidebar-link">演示基于异常比例熔断</a></li><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-05-05-SA%E5%AE%9E%E6%88%98-%E7%AC%AC11%E7%AB%A0-%E6%9C%8D%E5%8A%A1%E5%AE%B9%E9%94%99%E5%8A%A0%E9%A4%90-Sentinel%E6%A0%B8%E5%BF%83%E6%8A%80%E6%9C%AF%E4%B8%8E%E9%85%8D%E7%BD%AE%E8%A7%84%E5%88%99.html#演示基于异常数熔断" class="toc-sidebar-link">演示基于异常数熔断</a></li></ul></li><li><a href="/md/microservices/springcloudalibaba/2022-05-05-SA%E5%AE%9E%E6%88%98-%E7%AC%AC11%E7%AB%A0-%E6%9C%8D%E5%8A%A1%E5%AE%B9%E9%94%99%E5%8A%A0%E9%A4%90-Sentinel%E6%A0%B8%E5%BF%83%E6%8A%80%E6%9C%AF%E4%B8%8E%E9%85%8D%E7%BD%AE%E8%A7%84%E5%88%99.html#热点规则" class="toc-sidebar-link">热点规则</a><ul class="toc-sidebar-sub-headers"><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-05-05-SA%E5%AE%9E%E6%88%98-%E7%AC%AC11%E7%AB%A0-%E6%9C%8D%E5%8A%A1%E5%AE%B9%E9%94%99%E5%8A%A0%E9%A4%90-Sentinel%E6%A0%B8%E5%BF%83%E6%8A%80%E6%9C%AF%E4%B8%8E%E9%85%8D%E7%BD%AE%E8%A7%84%E5%88%99.html#热点规则概述" class="toc-sidebar-link">热点规则概述</a></li><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-05-05-SA%E5%AE%9E%E6%88%98-%E7%AC%AC11%E7%AB%A0-%E6%9C%8D%E5%8A%A1%E5%AE%B9%E9%94%99%E5%8A%A0%E9%A4%90-Sentinel%E6%A0%B8%E5%BF%83%E6%8A%80%E6%9C%AF%E4%B8%8E%E9%85%8D%E7%BD%AE%E8%A7%84%E5%88%99.html#演示热点规则" class="toc-sidebar-link">演示热点规则</a></li><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-05-05-SA%E5%AE%9E%E6%88%98-%E7%AC%AC11%E7%AB%A0-%E6%9C%8D%E5%8A%A1%E5%AE%B9%E9%94%99%E5%8A%A0%E9%A4%90-Sentinel%E6%A0%B8%E5%BF%83%E6%8A%80%E6%9C%AF%E4%B8%8E%E9%85%8D%E7%BD%AE%E8%A7%84%E5%88%99.html#演示热点高级选项规则" class="toc-sidebar-link">演示热点高级选项规则</a></li></ul></li><li><a href="/md/microservices/springcloudalibaba/2022-05-05-SA%E5%AE%9E%E6%88%98-%E7%AC%AC11%E7%AB%A0-%E6%9C%8D%E5%8A%A1%E5%AE%B9%E9%94%99%E5%8A%A0%E9%A4%90-Sentinel%E6%A0%B8%E5%BF%83%E6%8A%80%E6%9C%AF%E4%B8%8E%E9%85%8D%E7%BD%AE%E8%A7%84%E5%88%99.html#授权规则" class="toc-sidebar-link">授权规则</a><ul class="toc-sidebar-sub-headers"><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-05-05-SA%E5%AE%9E%E6%88%98-%E7%AC%AC11%E7%AB%A0-%E6%9C%8D%E5%8A%A1%E5%AE%B9%E9%94%99%E5%8A%A0%E9%A4%90-Sentinel%E6%A0%B8%E5%BF%83%E6%8A%80%E6%9C%AF%E4%B8%8E%E9%85%8D%E7%BD%AE%E8%A7%84%E5%88%99.html#授权规则概述" class="toc-sidebar-link">授权规则概述</a></li><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-05-05-SA%E5%AE%9E%E6%88%98-%E7%AC%AC11%E7%AB%A0-%E6%9C%8D%E5%8A%A1%E5%AE%B9%E9%94%99%E5%8A%A0%E9%A4%90-Sentinel%E6%A0%B8%E5%BF%83%E6%8A%80%E6%9C%AF%E4%B8%8E%E9%85%8D%E7%BD%AE%E8%A7%84%E5%88%99.html#演示授权规则" class="toc-sidebar-link">演示授权规则</a></li></ul></li><li><a href="/md/microservices/springcloudalibaba/2022-05-05-SA%E5%AE%9E%E6%88%98-%E7%AC%AC11%E7%AB%A0-%E6%9C%8D%E5%8A%A1%E5%AE%B9%E9%94%99%E5%8A%A0%E9%A4%90-Sentinel%E6%A0%B8%E5%BF%83%E6%8A%80%E6%9C%AF%E4%B8%8E%E9%85%8D%E7%BD%AE%E8%A7%84%E5%88%99.html#系统规则" class="toc-sidebar-link">系统规则</a><ul class="toc-sidebar-sub-headers"><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-05-05-SA%E5%AE%9E%E6%88%98-%E7%AC%AC11%E7%AB%A0-%E6%9C%8D%E5%8A%A1%E5%AE%B9%E9%94%99%E5%8A%A0%E9%A4%90-Sentinel%E6%A0%B8%E5%BF%83%E6%8A%80%E6%9C%AF%E4%B8%8E%E9%85%8D%E7%BD%AE%E8%A7%84%E5%88%99.html#系统规则概述" class="toc-sidebar-link">系统规则概述</a></li><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-05-05-SA%E5%AE%9E%E6%88%98-%E7%AC%AC11%E7%AB%A0-%E6%9C%8D%E5%8A%A1%E5%AE%B9%E9%94%99%E5%8A%A0%E9%A4%90-Sentinel%E6%A0%B8%E5%BF%83%E6%8A%80%E6%9C%AF%E4%B8%8E%E9%85%8D%E7%BD%AE%E8%A7%84%E5%88%99.html#演示系统规则" class="toc-sidebar-link">演示系统规则</a></li></ul></li><li><a href="/md/microservices/springcloudalibaba/2022-05-05-SA%E5%AE%9E%E6%88%98-%E7%AC%AC11%E7%AB%A0-%E6%9C%8D%E5%8A%A1%E5%AE%B9%E9%94%99%E5%8A%A0%E9%A4%90-Sentinel%E6%A0%B8%E5%BF%83%E6%8A%80%E6%9C%AF%E4%B8%8E%E9%85%8D%E7%BD%AE%E8%A7%84%E5%88%99.html#sentinelresource注解" class="toc-sidebar-link">@SentinelResource注解</a><ul class="toc-sidebar-sub-headers"><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-05-05-SA%E5%AE%9E%E6%88%98-%E7%AC%AC11%E7%AB%A0-%E6%9C%8D%E5%8A%A1%E5%AE%B9%E9%94%99%E5%8A%A0%E9%A4%90-Sentinel%E6%A0%B8%E5%BF%83%E6%8A%80%E6%9C%AF%E4%B8%8E%E9%85%8D%E7%BD%AE%E8%A7%84%E5%88%99.html#sentinelresource注解概述" class="toc-sidebar-link">@SentinelResource注解概述</a></li><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-05-05-SA%E5%AE%9E%E6%88%98-%E7%AC%AC11%E7%AB%A0-%E6%9C%8D%E5%8A%A1%E5%AE%B9%E9%94%99%E5%8A%A0%E9%A4%90-Sentinel%E6%A0%B8%E5%BF%83%E6%8A%80%E6%9C%AF%E4%B8%8E%E9%85%8D%E7%BD%AE%E8%A7%84%E5%88%99.html#演示-sentinelresource注解" class="toc-sidebar-link">演示@SentinelResource注解</a></li></ul></li><li><a href="/md/microservices/springcloudalibaba/2022-05-05-SA%E5%AE%9E%E6%88%98-%E7%AC%AC11%E7%AB%A0-%E6%9C%8D%E5%8A%A1%E5%AE%B9%E9%94%99%E5%8A%A0%E9%A4%90-Sentinel%E6%A0%B8%E5%BF%83%E6%8A%80%E6%9C%AF%E4%B8%8E%E9%85%8D%E7%BD%AE%E8%A7%84%E5%88%99.html#sentinel持久化" class="toc-sidebar-link">Sentinel持久化</a><ul class="toc-sidebar-sub-headers"><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-05-05-SA%E5%AE%9E%E6%88%98-%E7%AC%AC11%E7%AB%A0-%E6%9C%8D%E5%8A%A1%E5%AE%B9%E9%94%99%E5%8A%A0%E9%A4%90-Sentinel%E6%A0%B8%E5%BF%83%E6%8A%80%E6%9C%AF%E4%B8%8E%E9%85%8D%E7%BD%AE%E8%A7%84%E5%88%99.html#sentinel持久化概述" class="toc-sidebar-link">Sentinel持久化概述</a></li><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-05-05-SA%E5%AE%9E%E6%88%98-%E7%AC%AC11%E7%AB%A0-%E6%9C%8D%E5%8A%A1%E5%AE%B9%E9%94%99%E5%8A%A0%E9%A4%90-Sentinel%E6%A0%B8%E5%BF%83%E6%8A%80%E6%9C%AF%E4%B8%8E%E9%85%8D%E7%BD%AE%E8%A7%84%E5%88%99.html#实现sentinel的持久化" class="toc-sidebar-link">实现Sentinel的持久化</a></li></ul></li><li><a href="/md/microservices/springcloudalibaba/2022-05-05-SA%E5%AE%9E%E6%88%98-%E7%AC%AC11%E7%AB%A0-%E6%9C%8D%E5%8A%A1%E5%AE%B9%E9%94%99%E5%8A%A0%E9%A4%90-Sentinel%E6%A0%B8%E5%BF%83%E6%8A%80%E6%9C%AF%E4%B8%8E%E9%85%8D%E7%BD%AE%E8%A7%84%E5%88%99.html#关于星球" class="toc-sidebar-link">关于星球</a><ul class="toc-sidebar-sub-headers"><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-05-05-SA%E5%AE%9E%E6%88%98-%E7%AC%AC11%E7%AB%A0-%E6%9C%8D%E5%8A%A1%E5%AE%B9%E9%94%99%E5%8A%A0%E9%A4%90-Sentinel%E6%A0%B8%E5%BF%83%E6%8A%80%E6%9C%AF%E4%B8%8E%E9%85%8D%E7%BD%AE%E8%A7%84%E5%88%99.html#星球提供的服务" class="toc-sidebar-link">星球提供的服务</a></li><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-05-05-SA%E5%AE%9E%E6%88%98-%E7%AC%AC11%E7%AB%A0-%E6%9C%8D%E5%8A%A1%E5%AE%B9%E9%94%99%E5%8A%A0%E9%A4%90-Sentinel%E6%A0%B8%E5%BF%83%E6%8A%80%E6%9C%AF%E4%B8%8E%E9%85%8D%E7%BD%AE%E8%A7%84%E5%88%99.html#星球门票价格" class="toc-sidebar-link">星球门票价格</a></li></ul></li><li><a href="/md/microservices/springcloudalibaba/2022-05-05-SA%E5%AE%9E%E6%88%98-%E7%AC%AC11%E7%AB%A0-%E6%9C%8D%E5%8A%A1%E5%AE%B9%E9%94%99%E5%8A%A0%E9%A4%90-Sentinel%E6%A0%B8%E5%BF%83%E6%8A%80%E6%9C%AF%E4%B8%8E%E9%85%8D%E7%BD%AE%E8%A7%84%E5%88%99.html#写在最后" class="toc-sidebar-link">写在最后</a><ul class="toc-sidebar-sub-headers"></ul></li></ul></div></div></div></div></div> <div class="option-box"><img src="/images/system/wechat.png" class="nozoom"> <span class="show-txt">手机看</span> <div class="toc-container"><div class="pos-box"><div class="icon-arrow"></div> <div class="scroll-box" style="text-align:center"><span style="font-size:0.9rem">微信扫一扫</span> <img height="180px" src="https://api.qrserver.com/v1/create-qr-code/?data=https://binghe001.github.io/md/microservices/springcloudalibaba/2022-05-05-SA%E5%AE%9E%E6%88%98-%E7%AC%AC11%E7%AB%A0-%E6%9C%8D%E5%8A%A1%E5%AE%B9%E9%94%99%E5%8A%A0%E9%A4%90-Sentinel%E6%A0%B8%E5%BF%83%E6%8A%80%E6%9C%AF%E4%B8%8E%E9%85%8D%E7%BD%AE%E8%A7%84%E5%88%99.html" style="margin:10px;">
                可以<b>手机看</b>或分享至<b>朋友圈</b></div></div></div></div> <div class="option-box"><img src="/images/system/toggle.png" width="30px" class="nozoom"> <span class="show-txt">左栏</span></div> <div class="option-box"><img src="/images/system/xingqiu.png" width="25px" class="nozoom"> <span class="show-txt">星球</span> <div class="toc-container"><div class="pos-box"><div class="icon-arrow"></div> <div class="scroll-box" style="text-align:center"><span style="font-size:0.8rem;font-weight:bold;">实战项目<span style="font-size:8px;color:red;">「SpringCloud Alibaba实战项目」</span>、专属电子书、问题解答、简历指导、技术分享、晋升指导、视频课程</span> <img height="180px" src="/images/personal/xingqiu.png" style="margin:10px;"> <b>知识星球</b>：冰河技术
            </div></div></div></div> <div class="option-box"><img src="/images/system/wexin4.png" width="25px" class="nozoom"> <span class="show-txt">读者群</span> <div class="toc-container"><div class="pos-box"><div class="icon-arrow"></div> <div class="scroll-box" style="text-align:center"><span style="font-size:0.8rem;font-weight:bold;">添加冰河微信<span style="color:red;">(hacker_binghe)</span>进冰河技术学习交流圈「无任何套路」</span> <img src="/images/personal/hacker_binghe.jpg" height="180px" style="margin:10px;">
                PS：添加时请备注<b>读者加群</b>，谢谢！
              </div></div></div></div> <div class="option-box"><img src="/images/system/download-2.png" width="25px" class="nozoom"> <span class="show-txt">下资料</span> <div class="toc-container"><div class="pos-box"><div class="icon-arrow"></div> <div class="scroll-box" style="text-align:center"><span style="font-size:0.8rem;font-weight:bold;">扫描公众号，回复<span style="color:red;">“1024”</span>下载<span style="color:red;">100GB+</span>学习技术资料、PDF书籍、实战项目、简历模板等「无任何套路」</span> <img src="/images/personal/qrcode.png" height="180px" style="margin:10px;"> <b>公众号:</b> 冰河技术
              </div></div></div></div> <div class="option-box"><img src="/images/system/heart-1.png" width="25px" class="nozoom"> <span class="show-txt">赞赏我</span> <div class="toc-container"><div class="pos-box"><div class="icon-arrow"></div> <div class="scroll-box" style="text-align:center"><span style="font-size:0.8rem;font-weight:bold;">鼓励/支持/赞赏我</span> <img height="180px" src="/images/personal/encourage-head.png" style="margin:5px;"> <br>1. 不靠它生存但仍希望得到你的鼓励；
                <br>2. 时刻警醒自己保持技术人的初心；
              </div></div></div></div> <div title="SA实战 ·《SpringCloud Alibaba实战》第10章-服务容错：项目整合Sentinel实现限流与容错" class="option-box" style="padding-left:2px;text-align:center;"><a href="/md/microservices/springcloudalibaba/2022-05-03-SA实战-第10章-服务容错-Fegin整合Sentinel.html"><img src="/images/system/pre2.png" width="30px" class="nozoom"> <span class="show-txt">上一篇</span></a></div> <div title="SA实战 ·《SpringCloud Alibaba实战》第12章-服务网关：网关概述与核心架构" class="option-box" style="padding-left:2px;text-align:center;"><a href="/md/microservices/springcloudalibaba/2022-05-08-SA实战-第12章-服务网关-网关概述与核心架构.html"><img src="/images/system/next2.png" width="30px" class="nozoom"> <span class="show-txt">下一篇</span></a></div></div>  <!----> </aside></div><div class="global-ui"><div class="read-more-wrap" style="display:none;position:absolute;bottom:0px;z-index:9999;width:100%;margin-top:-100px;font-family:PingFangSC-Regular, sans-serif;"><div id="read-more-mask" style="position: relative; height: 200px; background: -webkit-gradient(linear, 0 0%, 0 100%, from(rgba(255, 255, 255, 0)), to(rgb(255, 255, 255)));"></div> <a id="read-more-btn" target="_self" style="position: absolute; left: 50%; top: 70%; bottom: 30px; transform: translate(-50%, -50%); width: 160px; height: 36px; line-height: 36px; font-size: 15px; text-align: center; border: 1px solid rgb(222, 104, 109); color: rgb(222, 104, 109); background: rgb(255, 255, 255); cursor: pointer; border-radius: 6px;">阅读全文</a> <div id="btw-modal-wrap" style="display: none;"><div id="btw-mask" style="position: fixed; top: 0px; right: 0px; bottom: 0px; left: 0px; opacity: 0.7; z-index: 999; background: rgb(0, 0, 0);"></div> <div id="btw-modal" style="position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); width: 300px; text-align: center; font-size: 13px; background: rgb(255, 255, 255); border-radius: 10px; z-index: 9999; font-family: PingFangSC-Regular, sans-serif;"><span id="btw-modal-close-btn" style="position: absolute; top: 5px; right: 15px; line-height: 34px; font-size: 34px; cursor: pointer; opacity: 0.2; z-index: 9999; color: rgb(0, 0, 0); background: none; border: none; outline: none;">×</span> <p id="btw-modal-header" style="margin-top: 40px; line-height: 1.8; font-size: 13px;">
                扫码或搜索：<span style="color: #E9405A; font-weight: bold;">冰河技术</span> <br>发送：<span id="fustack-token" class="token" style="color: #e9415a; font-weight: bold; font-size: 17px; margin-bottom: 45px;">290992</span> <br>即可<span style="color: #e9415a; font-weight: bold;">立即永久</span>解锁本站全部文章</p> <img src="/images/personal/qrcode.png" style="width: 180px; margin-top: 10px; margin-bottom: 30px; border: 8px solid rgb(230, 230, 230);"></div></div></div><div class="pay-read-more-wrap" style="display:none;position:absolute;bottom:0px;z-index:9999;width:100%;margin-top:-100px;font-family:PingFangSC-Regular, sans-serif;"><div id="pay-read-more-mask" style="position: relative; height: 200px; background: -webkit-gradient(linear, 0 0%, 0 100%, from(rgba(255, 255, 255, 0)), to(rgb(255, 255, 255)));"></div> <a id="pay-read-more-btn" target="_blank" style="position: absolute; left: 50%; top: 70%; bottom: 30px; transform: translate(-50%, -50%); width: 160px; height: 36px; line-height: 36px; font-size: 15px; text-align: center; border: 1px solid rgb(222, 104, 109); color: rgb(222, 104, 109); background: rgb(255, 255, 255); cursor: pointer; border-radius: 6px;">付费阅读</a></div></div></div>
    <script src="/assets/js/cg-styles.js?v=1653305936337" defer></script><script src="/assets/js/cg-4.js?v=1653305936337" defer></script><script src="/assets/js/cg-3.js?v=1653305936337" defer></script><script src="/assets/js/cg-299.js?v=1653305936337" defer></script><script src="/assets/js/cg-5.js?v=1653305936337" defer></script><script src="/assets/js/cg-6.js?v=1653305936337" defer></script><script src="/assets/js/cg-app.js?v=1653305936337" defer></script>
  </body>
</html>
